Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding Code Programmatically
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00147160
Message ID:
00147353
Views:
28
>Any ideas on how to add method code
>programmatically?

There is no way to directly add code to a method or procedure at run time. What VFP _does_ give us though is the magical '&'. Putting code into a variable and then issuing
&MyVar

executes the code in the variable. What you will quickly find, however, is that macro substitution only works one line at a time. This is ok if the code you want to run is simple and linear, but not ok if you have any loops or controls structures. But... there is a way :)

Randy Pearson, in all of his genious, has written and placed in the public domain a program called CodeBlock that takes a program in the form of a text string (so you can store it in a memo file, text file, or whatever) and breaks down the control structures into workable chunks and executes them in the order you intended with '&'. I believe CodeBlock is available here in the files section.

Why can't you just build a prg file and execute it? Because it can't run if it can't be compiled, and you are not licensed to distribute the VFP compiler. There is a littler known way to do this though, but the user has to have a copy of VFP on his machine. You can actually run VFP as an OLE Server and use it to compile code. The syntax would go like

oVFP = CREATEOBJECT('VisualFoxPro.Application')
oVFP.DoCmd('Compile c:\myprg.prg')
RELEASE oVFP

You would want to be very careful where you implement something like this, because the speed would in most cases be prohibitive.
Erik Moore
Clientelligence
Previous
Reply
Map
View

Click here to load this message in the networking platform