Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
OTHER >>  #DEFINE YOUR TABLES

  Boudewijn Lutgerink
  Where is Boudewijn Lutgerink?
 Hoonaardstraat, Driel
 Netherlands
 Boudewijn Lutgerink



While working on an application I wanted to make that app more generic so I can market it easier.
Ever since last year I use one exe only that opens a table, in that table is the code for the app. I use then the execscript() to execute the code. ("Blame" Andy Kramek for this extremely useful trick on metadata).

For code maintenance I created my own exe that opens the table so I can add/alter code without having to recompile my exe.

One useful thing I found out is that you can, in such code, use the #DEFINE for defining the tablenames.
So the memofield in my table can have code like

#define tbl2Open Customers
#define tblAnotherTable2Open Employees
use tbl2Open in 0 shared
use tblAnotherTable2Open in 0 shared
...

Of course, as you can see from this code. Using an #INCLUDE works just as easy, the only thing you have to keep in mind is that you have to ship the .H file (or whatever you name the includefile) with your app.

This made flexible programming a lot easier for me.

FEEDBACK

suhas hegde @ 12/19/2007 11:05:53 AM
Good Point

But I would prefer to enclose the Define in [] for better readbility
eg:
Use [tbl2Open] in 0 shared

So that When ever i see that line i would sure that it is #defined ..

Also

With shipping the .h files are you reffering to #include directive ?

Thanx

Boudewijn Lutgerink @ 12/19/2007 3:54:35 PM
Normally a header file does contain #define statements (basically). So yes that is what I mean.
The ExecScript() function first compiles the code in the memofield and then executes it.
As for enclosing the defines in square brackets, that is a matter of taste, not really necessary in my opinion.

Mike Yearwood @ 12/20/2007 6:59:18 PM
Hi Boudewijn

Interesting approach. Does it not worry you that you've completely exposed your source code? I had problems (for a time) with execscript accessing classes defined in the main exe and decided to limit my use of it.

I agree with you on the style topic. IMO [ ] should only be used for array references. My personal preference for #DEFINEs is to preface the variables with k - for constant. ;)

DEFINE kStartDate {^2000-01-02}

That lets me know it's a constant.

Boudewijn Lutgerink @ 2/5/2008 11:44:55 AM
well, the code is not completely exposed Mike.
What I left out is the fact that I first encrypt it before storing it in my tables.
This sample is somewhat simplified.
I actually do an execScript(decrypt(MyField, SomeKey)).
It does slow down things a littlebit but not noticeable since I use small codesnippets.
As to the style thing. I normally use "def" as a prefix for my #define constants. I left that out as well.

Mike Yearwood @ 12/11/2008 7:56:42 PM
That reminds me. I use k as a prefix for Konstants ;) kl, kn, kd etc.



Your Name: 
Your Feedback: 

Spam Protection:
Enter the code shown: