Nesting #INCLUDES in Visual FoxPro

It appears the the first time a constant is #DEFINEd it can not be changed. This is true through the #INCLUDEs also.

So, for example, if put into header.h:

#DEFINE MyName "Bob"
#INCLUDE header2.h

Then in header2.h put:

#DEFINE MyName "Robert"

Then include header.h in your PRG the constant will be assigned as "Bob.

But, if you change the header.h file to read:

#INCLUDE header2.h
#DEFINE MyName "Bob"

Then include it in your prg the constant will be "Robert".

If you want to ensure that a definition does not allready exsit you can undef it first. So, for example, if I have header.h of

#DEFINE MyName "Bob"
#INCLUDE header2.h

and a header2.h of:

#UNDEF MyName
#DEFINE MyName "Robert"

Then use header.h in my PRG the contsant will be "Robert".

Also, I want to point out that they docs says:

"You can redefine a #DEFINE only if you do not change the value. If you change the #DEFINE to a different value, Visual FoxPro generates an error."

I did not find this to be true. Unless there is some setting that controls this. Not sure if this is a bug or an error in the doc. But, I can see this raising an error as very annoying.

Also, ensure that when you are testing this... if you are only changing the headers you re-save your program which will cause it to recompile assuming you have SET DEVELOPMENT ON. This is because the constants are a compile time replacement.