Saturday, March 05, 2005

Quick & Dirty Hook Program

Most of the time, we need hook(s) to allow custom program to be run before/after certain process. There are many ways to accomplish it in VFP, ex. add-in manager (as class browser does), EXECSCRIPT() to run code stored in memo field or external app.

However, we need some time to design and implement add-in manager. Also, EXECSCRIPT() function only available in VFP8 and later. A quick and dirty way to do this is to create an external .app and call it using DO statement.
IF FILE("premyprcs.app")
DO ("premyprcs") WITH para1, para2, ...
ENDIF
The downside of doing this is we can't return value from external .app to report status. The workaround is, pass an additional parameter by reference and assign the return value to it within the external .app.

BTW, remember to use DO ("premyprcs") instead of DO premyprcs to prevent VFP project manager to search for the external .app file and return error during compilation.

2 Comments:

At 3:38 PM, Blogger wOOdy said...

The params of the DO command are BY REFERENCE per default. Functions are BY VALUE, but DO is BY REFERENCE. Therefor, any parameter you use is automatically two-way.

 
At 9:14 AM, Blogger Chan Kok Kiet (John Jones) said...

Thank you for comment.
What I meant is we have no way to :
DO ("mypremyprcs.app") WITH para1, para2 TO lnRetval

Instead, we got to
DO ("mypremyprcs.app") WITH para1, para2, lnRetval

IF lnRetVal < 0
*--Do whatever
ENDIF

 

Post a Comment

<< Home