Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

#DEFINE & Global Variables 1

Status
Not open for further replies.

Scott24x7

Programmer
Jul 12, 2001
2,828
JP
Couple of questions on this topic:

1) Are #DEFINE's treated as "Public", if they are included in the .H file, and called during your system setup?

2) In the "Olden" days of Fox2.6, the more "Public" variables you had, the more memory it used, and the system performance could easily be impacted by that. Is that still the case in VFP?
Thanks,
-Scott
 
<<Are #DEFINE's treated as &quot;Public&quot;, if they are included in the .H file, and called during your system setup?>>

No. #DEFINES and #INCLUDES only have &quot;scope&quot; in the physical file that they are part of. This is because they're not memvars... they are preprocessor directives. The VFP p-code compiler &quot;looks&quot; for these defines in the code and replaces the define/include value with its literal alternative:

SELECT * FROM MyDBF WHERE KeyVal BETWEEN dnLowRef And dnHiRef

becomes

#DEFINE dnLowRef 1
#DEFINE dnHiRef 9999

SELECT * FROM MyDBF WHERE KeyVal BETWEEN 1 and 9999


<<In the &quot;Olden&quot; days of Fox2.6, the more &quot;Public&quot; variables you had, the more memory it used, and the system performance could easily be impacted by that. Is that still the case in VFP?>>

Yup. BAD publics... BAD BAD BAD publics.

Regards,
Thom C.
 
Publics are like formsets, everyone says they are bad.

Well, I think not....they are only bad if used wrongly...;-)

In essence, the ideal VFP application has only one public being the global variable for the application object.

All other things used globally can be a property of the global application object.

#DEFINE or Named constants are only for the ease of programming.

MAX_AMOUNT_1000 is easier to read than 1000 when found in code.

HTH,
Weedz (Wietze Veld)
My private project:CrownBase source code can be downloaded !!
 
Weedz,

<<MAX_AMOUNT_1000 is easier to read than 1000 when found in code.>>

It's also easier to institute a global change. If you've got

#DEFINE dnMaxAmount 1000

in several places in a piece of code and someday the &quot;max amount&quot; goes to say 1250, you'll only have to change that value in one place, the define statement.

Regards,
Thom C.
 
TOmC,

you are right, sometimes I do not give the best exammples in this forum, but I have read Code Complete and I know about good naming and MAX_AMOUNT_1000 is not the best example, I fully admit it. ;-)

MAX_AMOUNT would have been better.

I forgot about the global change of values, I have had the pleasure of using this methodoly several times and it really saves a lot of work. (Long live OOP as well).

Cheers,

Weedz (Wietze Veld)
My private project:CrownBase source code can be downloaded !!
 
I've been watching this thread and have a few questions regarding #DEFINE and #INCLUDE. Can these commands be used in a Form or Class? If so, where, and are they available throughout the methods in the form or must they be replicated in each method where you want to take advantage of them?

Steve
 
Steve,

<<#DEFINE and #INCLUDE... Can these commands be used in a Form or Class?>>

Yes. To INCLUDE a file in a form or class, via the main menu:
>Form(or Class)>Include File...

Put the properly pathed include file in the dialog box.

The include file will be available throughout the form/class.


You can use #DEFINEs in methods/events and the placement within the method is not absolutely critical. However, the #DEFINE must preceed the use of the define clause in a command and the #DEFINE is only valid within the method.

For more information see &quot;#DEFINE ... #UNDEF Preprocessor Directive&quot; in the VFP help.


Hey Weedz,
<<sometimes I do not give the best exammples in this forum>>
Yer spelling needs work too ;-)


Regards,
Thom C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top