What Tore Bleken says.
In that respect, to not need to write these defines in every method using them, you have the menu item Class->Include File. What .h file you include there is then valid and usable in the whole class in every method.
Just to stress it out once more: A declaration is not like a global variable scoped with a biggest scope when done in the main.prg. Declarations are only precompiler directives and used within one method compiled besides the class include file exception.
There is one more larger scoped aspect of include files, that is the "Default Include File" in the File Locations tab of the options dialog:
Help said:
Default Include File
Specifies a default header file of predefined compile-time constants included automatically with user-defined classes, forms, or form sets. This option is empty by default and corresponds to the _INCLUDE System Variable.
So it is
not included in PRGs and from the top of my head I think it rather gives a headache than helping, as any specifically assigned Include File in a class overrides the default instead of extending it, I think - anyway obce I tried it it wasn't helpful. I think it can't be retrofitted anyway, it only acts as default for new classes and thus only helps you not forget to put some include into a vcx class.
Also notice, the #INCLUDE directive allows you to include include files within include files, too, so they can be separated per concern and still be loaded within each other, even wrapped with some #IFDEF #IFNDEF logic, but VFP has a nasty behaviour not easily spotted: If you specify relative paths in #Include directives in code they are not taken relative to the PRG or VCX location but relative to whatever SET DEFAULT or CD path current directory you are at when compiling. One fraework I use and one project I inherited need you to CD into project home before editing PRGs or building a project because of that and I think it is an annoyance and bad design. At this point some may disagree and state other experience, but notice this often remains unnoticed and becomes a sleeping watchdog, if you build without using the recompile all option, then most files are not processed again also in regard of misplaced header files. But when you do, suddenly the includes don't work. Also for that reason I see double header files in one project I inherited, someone squashed the issue by putting smae include files in several folders, so they are always found, but of course that becomes a nightmare to maintain as all of them need all changes.
I limit myself to include files you specify in VCX classes, as that works best and the compiler manages to find header files from the info stored in the vcx not depending on current directory when compiling. Still I make it as easy to have a complete set of files when reusing classes, so I put .h files within the libs folder of classes and not in a separate /includes/ folder, neither parallel to /libs/ nor as sub folder /libs/includes. I name includes files same as the library, though include files are to be specified per class, they are not applied to all classes of the whole vcx library, when specified within one class design session. But at least they have the advantage to be applicable in every method of the class.
Therefore I also prefer to design visual classes instead of PRG classes. You can argue and say in contrary despite needing to CD into some folder for working with a project, you can a) make that something the envirnment manager within the task pane takes care of and b) once used to it have a stronger weapon with all the detail possibilities of preprocessor directives. I mainly do without any #IF(N')DEF or other advanced preprocessor directives, though I know some applications for it, because this is a beast more than it is helpful, and I like to have my build setting for fast builds without recompile all. To take care of Tores warning, If I change the .h file I also once compile with recompile all, if the header is used in many places or "touch" the relevant classlib(s) by opening them and adding a space somwehere, other trickery is possible with foxtouch within foxtools.fll to make VFP think files need recompilation, but that's also a hack. VFP unfortunatly is not as intelligent to detect a .h change as need for recompilation of classes, as the compiler does not look from that side, it mainly looks for last changed dates of prg or vcx or vct or scx/sct etc files and not of .h files.
Overall, it's a good idea to make less use of includes and defines. I often use them for the same goal, though. Not only for page or other numbers having certain meaning, also for meanings of boolean parameters even in native functions, which yo don't find in Foxpro.h in Home(). For example
Code:
#DEFINE cnCommitCurrentRowOnly 0
#DEFINE cnCommitAllRowsOnErrorStop 1
#DEFINE cnCommitAllRowsOnErrorContinue 2
[highlight #FCE94F]#DEFINE clForceUpdates .T.
#DEFINE clDontForceUpdates .F.[/highlight]
TABLEUPDATE(cnCommitAllRowsOnErrorContinue, [highlight #FCE94F]clForceUpdates[/highlight], ALIAS(), laErraticRecnos)
That is easier to understand than TABLEUPDATE(2, [highlight #FCE94F].T.[/highlight], ALIAS(), laErraticRecnos), isn't it? So it also pays to specify constants for other than numeric types with a meaning not showing when you don't know the parameter name is lForce - besides even that does not tell what is forced or not forced.
Bye, Olaf.