Is there a way to grab a method's source code text programatically?

34 views
Skip to first unread message

Jorge

unread,
Jun 1, 2012, 4:53:19 PM6/1/12
to 4D-Tech
Hi,

I'd like to find a way to grab a method's source code as text to save
it onto a file. Any ideas?

Thanks,
--
Jorge.

Sam Burnell

unread,
Jun 1, 2012, 5:09:08 PM6/1/12
to 4d-...@googlegroups.com
Copy paste???
> --
> You are subscribed to 4D-...@googlegroups.com
> To unsubscribe: mailto:4D-Tech-u...@googlegroups.com
> Visit: http://groups.google.com/group/4D-Tech
>
> To contact the moderators, please send an email to Administrat...@googlegroups.com

Douglas von Roeder

unread,
Jun 1, 2012, 5:11:00 PM6/1/12
to 4d-...@googlegroups.com
Grab a copy of API Pack from pluggers.nl
--
Douglas von Roeder

Jorge

unread,
Jun 1, 2012, 5:17:12 PM6/1/12
to 4d-...@googlegroups.com
Thanks but no, thanks. I need to find a way to save all the method's sources to a directory to control versions with git.

Any ideas?

--
Jorge.

Jorge

unread,
Jun 1, 2012, 5:22:56 PM6/1/12
to 4d-...@googlegroups.com
I've done that already, but I don't see where/what should I use to get a method's source as text?

Do I have to read some resources of the structure?

Thanks,
--
Jorge.

Douglas von Roeder

unread,
Jun 1, 2012, 5:26:58 PM6/1/12
to 4d-...@googlegroups.com
Check out the demo. It uses most of the commands that you'll need.

API Pack is a superb product. I used it two years ago to modify, store, and deploy about 700 methods that were candidates for modification when adding a Flex front end to an application. Thanks to API Pack, I was able to extract code, parse it, modify it, and save the methods.

--
Douglas von Roeder

Jorge

unread,
Jun 1, 2012, 5:46:33 PM6/1/12
to 4d-...@googlegroups.com
Yeah, it's there: 4D_GetMethodText and 4D_GetMethodNames, cool.

Do you know if that does run in 4D v2003.8 ?

Thanks!
--
Jorge.

Douglas von Roeder

unread,
Jun 1, 2012, 5:50:34 PM6/1/12
to 4d-...@googlegroups.com
I would expect so. Grab the older version and check the docs or try it and let us know.

--
Douglas von Roeder

Jorge

unread,
Jun 1, 2012, 5:51:05 PM6/1/12
to 4d-...@googlegroups.com
Is there a way to the opposite too?

I mean, re-write a method with some given text?

I'd like to be able to `git pull origin master` and then run some method to merge the changes into my structure...

Any ideas?

Thanks,
--
Jorge.

Douglas von Roeder

unread,
Jun 1, 2012, 5:54:25 PM6/1/12
to 4d-...@googlegroups.com
Jorge:

API Pack works very nicely - dunno about git.

Good luck with your project!

--
Douglas von Roeder

Jorge

unread,
Jun 1, 2012, 6:03:54 PM6/1/12
to 4d-...@googlegroups.com
On Jun 1, 2012, at 11:54 PM, Douglas von Roeder wrote:

> Jorge:
>
> API Pack works very nicely - dunno about git.

Forget git!

Is there a way to *programmatically* re-write a method (of an interpreted, non-compiled DB, of course) from a source text file or var?

> Good luck with your project!

Thanks :-P
--
Jorge

Jorge

unread,
Jun 2, 2012, 4:43:54 AM6/2/12
to 4d-...@googlegroups.com
Oh yes, it's there too: 4D_SetMethodText
--
Jorge.

Pat Bensky

unread,
Jun 2, 2012, 5:43:16 AM6/2/12
to 4d-...@googlegroups.com
Nigel Greenlee has created a clever module that does that ...

Pat


--
You are subscribed to 4D-...@googlegroups.com
To unsubscribe: mailto:4D-Tech-u...@googlegroups.com
Visit: http://groups.google.com/group/4D-Tech

To contact the moderators, please send an email to Administrat...@googlegroups.com



--
*************************************************
CatBase - The Database Publishing Solution
tel: +44 (0) 1462 454522
fax: +44 (0) 1462 454566
w: http://www.catbase.com
skype: pat.bensky
Find great gift ideas at GiftGofers.com!
*************************************************

Jorge

unread,
Jun 4, 2012, 6:13:59 AM6/4/12
to 4d-...@googlegroups.com
On Jun 1, 2012, at 11:26 PM, Douglas von Roeder wrote:

> Check out the demo. It uses most of the commands that you'll need.
>
> API Pack is a superb product. I used it two years ago to modify, store, and deploy about 700 methods that were candidates for modification when adding a Flex front end to an application. Thanks to API Pack, I was able to extract code, parse it, modify it, and save the methods.

Douglas,

What about the Database Methods, and the Form Methods & Triggers?

Is there any way to grab those too?

Thank you,
--
Jorge.

Douglas von Roeder

unread,
Jun 4, 2012, 12:09:41 PM6/4/12
to 4d-...@googlegroups.com
Jorge:

Try it and let us know what you find.

--
Douglas von Roeder



--
Jorge.

Jorge

unread,
Jun 5, 2012, 3:55:05 PM6/5/12
to 4d-...@googlegroups.com
On Jun 4, 2012, at 6:09 PM, Douglas von Roeder wrote:
>
> On Mon, Jun 4, 2012 at 3:13 AM, Jorge <jo...@jorgechamorro.com> wrote:
>
>> What about the Database Methods, and the Form Methods & Triggers?
>>
>> Is there any way to grab those too?
>>
>> Thank you,
>>
> Jorge:
>
> Try it and let us know what you find.

Hi,

The problem is that API Get Method Names(names; IDs) doesn't return any Database Methods such as "On Startup", "On Server Startup", "On Web Connection", etc.

If I try to get their IDs with calls such as API Get Method ID ("On Web Connection"), I always get a 0.

If I try to 4D_GetMethodText ("On Web Connection") it gives me a "".

Douglas von Roeder

unread,
Jun 5, 2012, 4:19:26 PM6/5/12
to 4d-...@googlegroups.com
No ideas here.

--
Douglas von Roeder

Sent from my iPhone

Jorge

unread,
Jun 13, 2012, 12:35:01 PM6/13/12
to 4d-...@googlegroups.com
On Jun 5, 2012, at 10:19 PM, Douglas von Roeder wrote:
> On Jun 5, 2012, at 12:55 PM, Jorge <jo...@jorgechamorro.com> wrote:
>> On Jun 4, 2012, at 6:09 PM, Douglas von Roeder wrote:
>>> On Mon, Jun 4, 2012 at 3:13 AM, Jorge <jo...@jorgechamorro.com> wrote:
>>>
>>>> What about the Database Methods, and the Form Methods & Triggers?
>>>>
>>>> Is there any way to grab those too?
>>>>
>>>> Thank you,
>>>>
>>> Jorge:
>>>
>>> Try it and let us know what you find.
>>
>> Hi,
>>
>> The problem is that API Get Method Names(names; IDs) doesn't return any Database Methods such as "On Startup", "On Server Startup", "On Web Connection", etc.
>>
>> If I try to get their IDs with calls such as API Get Method ID ("On Web Connection"), I always get a 0.
>>
>> If I try to 4D_GetMethodText ("On Web Connection") it gives me a "".
>>
>> Any ideas?
>>
>> Thanks,
>
> No ideas here.
>
> (Sent from his iPhone)


Thank you Douglas.

I've made some progress.

I can get all the methods' ids with API Get Resource ID List ("CC4D";$ids), and I've modified slightly 4D_GetMethodText(methodName) to become 4D_GetMethodTextById(methodID).

Now I definitely know that I *can* grab "On Startup", "On Server Startup", etc, too, but I'd need to know how to map "On Startup" to its ID, "On Server Startup" to its ID, etc.

Any ideas, please?

Thanks in advance,
--
Jorge.

Douglas von Roeder

unread,
Jun 13, 2012, 12:49:27 PM6/13/12
to 4d-...@googlegroups.com
Jorge:

Create a project method named "On_Startup".

Open the database method "On Startup".

Copy the contents of the database method "On Startup" to the project method named "On_Startup".

Close the window for the database method "On Startup".

Close the window the project method named "On_Startup".

You can now access the code that runs in the database method "On Startup" by accessing the code in the project method named "On_Startup".


Q.E.D.

--
Douglas von Roeder



--
Jorge.

Jorge

unread,
Jun 13, 2012, 1:57:30 PM6/13/12
to 4d-...@googlegroups.com
On Jun 13, 2012, at 6:49 PM, Douglas von Roeder wrote:
>
> On Wed, Jun 13, 2012 at 9:35 AM, Jorge <jo...@jorgechamorro.com> wrote:
>>
>> I've made some progress.
>>
>> I can get all the methods' ids with API Get Resource ID List ("CC4D";$ids), and I've modified slightly 4D_GetMethodText(methodName) to become 4D_GetMethodTextById(methodID).
>>
>> Now I definitely know that I *can* grab "On Startup", "On Server Startup", etc, too, but I'd need to know how to map "On Startup" to its ID, "On Server Startup" to its ID, etc.
>>
>> Any ideas, please?
>
> Jorge:
>
> Create a project method named "On_Startup".
>
> Open the database method "On Startup".
>
> Copy the contents of the database method "On Startup" to the project method named "On_Startup".
>
> Close the window for the database method "On Startup".
>
> Close the window the project method named "On_Startup".
>
> You can now access the code that runs in the database method "On Startup" by accessing the code in the project method named "On_Startup".

Thank you Douglas, but I want to grab the real ones.

Why on earth would I want to duplicate "On Startup", "On Server Startup", "On Web Connection", etc?
--
Jorge.

Douglas von Roeder

unread,
Jun 13, 2012, 2:18:37 PM6/13/12
to 4d-...@googlegroups.com
Jorge:

I don't want duplicates either and, if you follow my instructions, you will not have duplicate method names.

"On Startup" #"On_Startup"

Reading comprehension is important.

I hope you can take advantage of the help that I've provided. At this point, there's nothing more to add.
 
--
Douglas von Roeder



--
Jorge.

Paul Medland

unread,
Jun 13, 2012, 2:22:42 PM6/13/12
to 4d-...@googlegroups.com
You are not duplicating the code. We have single lines of code in all our
database methods which call a project method. Project methods are named
the same except with underscores in the name. As mentioned by Doug, doing
this would at least allow you to extract the code of your database methods.
Paul M

Jorge

unread,
Jun 13, 2012, 5:13:40 PM6/13/12
to 4d-...@googlegroups.com
On Jun 13, 2012, at 8:18 PM, Douglas von Roeder wrote:
> On Wed, Jun 13, 2012 at 10:57 AM, Jorge <jo...@jorgechamorro.com> wrote:
> On Jun 13, 2012, at 6:49 PM, Douglas von Roeder wrote:
> >
> > On Wed, Jun 13, 2012 at 9:35 AM, Jorge <jo...@jorgechamorro.com> wrote:
> >>
> >> I've made some progress.
> >>
> >> I can get all the methods' ids with API Get Resource ID List ("CC4D";$ids), and I've modified slightly 4D_GetMethodText(methodName) to become 4D_GetMethodTextById(methodID).
> >>
> >> Now I definitely know that I *can* grab "On Startup", "On Server Startup", etc, too, but I'd need to know how to map "On Startup" to its ID, "On Server Startup" to its ID, etc.
> >>
> >> Any ideas, please?
> >
> > Jorge:
> >
> > Create a project method named "On_Startup".
> >
> > Open the database method "On Startup".
> >
> > Copy the contents of the database method "On Startup" to the project method named "On_Startup".
> >
> > Close the window for the database method "On Startup".
> >
> > Close the window the project method named "On_Startup".
> >
> > You can now access the code that runs in the database method "On Startup" by accessing the code in the project method named "On_Startup".
>
> Thank you Douglas, but I want to grab the real ones.
>
> Why on earth would I want to duplicate "On Startup", "On Server Startup", "On Web Connection", etc?
>
>
> Jorge:
>
> I don't want duplicates either and, if you follow my instructions, you will not have duplicate method names.
>
> "On Startup" #"On_Startup"
>
> Reading comprehension is important.

Reading comprehension is important? Don't be a twit!

> I hope you can take advantage of the help that I've provided. At this point, there's nothing more to add.

What you propose is a very bad idea: consider what would happen if someone touches the real "On Web Connection" *and* forgets to copy-paste it into "On_Web_Connection"?

I know how to get the source text of any DataBase Method: there's no need to copy-paste them as Project Methods renamed with underscores.

The only thing that I still need to find out is a way to determine the CC4D resource ID of the "On xxx" DataBase Methods.

Thank you very much.
--
Jorge.

Jorge

unread,
Jun 13, 2012, 5:15:20 PM6/13/12
to 4d-...@googlegroups.com
On Jun 13, 2012, at 8:22 PM, Paul Medland wrote
> On 12/06/13 1:57 PM, "Jorge" <jo...@jorgechamorro.com> wrote:
>>
>>
>> Thank you Douglas, but I want to grab the real ones.
>>
>> Why on earth would I want to duplicate "On Startup", "On Server Startup",
>> "On Web Connection", etc?
>>
> You are not duplicating the code. We have single lines of code in all our
> database methods which call a project method. Project methods are named
> the same except with underscores in the name. As mentioned by Doug, doing
> this would at least allow you to extract the code of your database methods.

Hi Paul,

I already found a way to grab the source text of any method. I just need to know how to find the CC4D rsrc ID of the DataBase Methods.

What Douglas is proposing is a *very* bad idea (for any reasons) and I don't want to and I'm not going to do it so.

Cheers,
--
Jorge.

Jorge

unread,
Jun 13, 2012, 5:19:12 PM6/13/12
to 4d-...@googlegroups.com
On Jun 13, 2012, at 11:15 PM, Jorge wrote:
>
>
> What Douglas is proposing is a *very* bad idea (for any reasons) and I don't want to and I'm not going to do it so.
>
> Cheers,

s/any/many/g
--
Jorge.

Rob Laveaux

unread,
Jun 13, 2012, 5:54:48 PM6/13/12
to 4d-...@googlegroups.com

On 13 jun. 2012, at 18:35, Jorge <jo...@jorgechamorro.com> wrote:

> Now I definitely know that I *can* grab "On Startup", "On Server Startup", etc, too, but I'd need to know how to map "On Startup" to its ID, "On Server Startup" to its ID, etc.

Hi Jorge,

Have a look at the DBPR resource. It contains the resource IDs of the various database methods.

HTH,

- Rob Laveaux

--------------------------------------------------------
Pluggers Software
Bleriotlaan 62
2497 BM Den Haag
The Netherlands

Email: rob.l...@pluggers.nl
Website: http://www.pluggers.nl

--------------------------------------------------------



Douglas von Roeder

unread,
Jun 13, 2012, 5:59:45 PM6/13/12
to 4d-...@googlegroups.com
Jorge:

Looks like you've found a solution. Great.

--
Douglas von Roeder



--
Jorge.

Jorge

unread,
Jun 14, 2012, 5:07:49 AM6/14/12
to 4d-...@googlegroups.com
On Jun 13, 2012, at 11:54 PM, Rob Laveaux wrote:
>
> On 13 jun. 2012, at 18:35, Jorge <jo...@jorgechamorro.com> wrote:
>
>> Now I definitely know that I *can* grab "On Startup", "On Server Startup", etc, too, but I'd need to know how to map "On Startup" to its ID, "On Server Startup" to its ID, etc.
>
> Hi Jorge,
>
> Have a look at the DBPR resource. It contains the resource IDs of the various database methods.
>
> HTH,
>
> - Rob Laveaux


Indeed, that helps a lot!


C_BLOB($blob)
C_LONGINT($id;$err)
ARRAY INTEGER($methodIDs;0)
ARRAY STRING(31;$methodNames;0)

API Get Method Names ($methodNames;$methodIDs)

$err:=API Get Indexed Resource ("DBPR";1;$blob)

If ($err=0)

$id:=$blob{0}*256+$blob{1}
If ($id#0xFFFF)
INSERT ELEMENT($methodNames;1)
INSERT ELEMENT($methodIDs;1)
$methodNames{1}:="On Startup"
$methodIDs{1}:=$id
End if

$id:=$blob{2}*256+$blob{3}
If ($id#0xFFFF)
INSERT ELEMENT($methodNames;1)
INSERT ELEMENT($methodIDs;1)
$methodNames{1}:="On Server Startup"
$methodIDs{1}:=$id
End if

$id:=$blob{4}*256+$blob{5}
If ($id#0xFFFF)
INSERT ELEMENT($methodNames;1)
INSERT ELEMENT($methodIDs;1)
$methodNames{1}:="On Exit"
$methodIDs{1}:=$id
End if

$id:=$blob{6}*256+$blob{7}
If ($id#0xFFFF)
INSERT ELEMENT($methodNames;1)
INSERT ELEMENT($methodIDs;1)
$methodNames{1}:="On Server Shutdown"
$methodIDs{1}:=$id
End if

$id:=$blob{8}*256+$blob{9}
If ($id#0xFFFF)
INSERT ELEMENT($methodNames;1)
INSERT ELEMENT($methodIDs;1)
$methodNames{1}:="On Server Open Connection"
$methodIDs{1}:=$id
End if

$id:=$blob{10}*256+$blob{11}
If ($id#0xFFFF)
INSERT ELEMENT($methodNames;1)
INSERT ELEMENT($methodIDs;1)
$methodNames{1}:="On Web Connection"
$methodIDs{1}:=$id
End if

$id:=$blob{12}*256+$blob{13}
If ($id#0xFFFF)
INSERT ELEMENT($methodNames;1)
INSERT ELEMENT($methodIDs;1)
$methodNames{1}:="On Server Close Connection"
$methodIDs{1}:=$id
End if

$id:=$blob{14}*256+$blob{15}
If ($id#0xFFFF)
INSERT ELEMENT($methodNames;1)
INSERT ELEMENT($methodIDs;1)
$methodNames{1}:="On Web Authentication"
$methodIDs{1}:=$id
End if
End if


Thank you very much Rob.

Cheers,
--
Jorge.

Jorge

unread,
Jun 16, 2012, 3:27:58 PM6/16/12
to 4d-...@googlegroups.com
On Jun 14, 2012, at 11:07 AM, Jorge wrote:
> On Jun 13, 2012, at 11:54 PM, Rob Laveaux wrote:
>>
>> Hi Jorge,
>>
>> Have a look at the DBPR resource. It contains the resource IDs of the various database methods.
>>
>> HTH,
>
> Indeed, that helps a lot!
>
> <SNIP>

Hi,

I've uploaded what I've got so far to github: <http://github.com/xk/4D-to-GIT> , so 4D-to-GIT is now officially a free open-source project.

I'm using ds_GetTriggerInfos() from the DynamicStructure plugin to get the trigger methods' IDs:

<https://github.com/xk/4D-to-GIT/blob/master/GitExportar.txt#L114-129>

But I need to find another way to do it because DynamicStructure isn't free.

Is there any way to obtain the triggers' IDs with the API Pack alone?

Any ideas/pointers/suggestions?

Thank you very much,
--
Jorge.
Reply all
Reply to author
Forward
0 new messages