Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
#DEFINE idiosyncracy
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00559473
Message ID:
00559606
Vues:
13
Hi!

All #DEFINE directives are processed by VFP in order they're appear in the code for COMPILATION process. This means:
Let assume you have 2 PRG files, AAA and BBB. AAA contains #DEFINE, and BBB use that define constant. You can find that sometimes BBB throws error and sometimes does not. Why? Because sometimes AAA compiled BEFORE BBB, and sometimes after. ALL #DEFINE directives are stored in the memory during the compilation process, they're always public to ALL modules (there is also #UNDEFINE directive that can make it local to some code snippet by defining constant than un-defining it again). In your case the situation is the same - sometimes Init method code is compiled first, and sometimed Click method. Usually it is depended on which method was edited last by the class designer.

MS do not recommend to use #DEFINEs are in the event/method in which they are not defined, just because it is not predictable or not reliable suggestion about the order of compilation of VFP code snippets and modules. For classes and forms it is recommended to use the Include file that you can assign from the appropriate class or form menu. This INCLUDE file for sure will be processed BEFORE compilation of any code of that class.

HTH.

>To All,
>
>While fooling around with #DEFINE statements I came up with this:
>
>* note: This is a copy of the ViewCode.prg generated from the class browser...
>the form was created visually.
>
>
DEFINE CLASS bform1 AS bform
>	Name = "Bform1"
>
>	ADD OBJECT bcommandbutton1 AS bcommandbutton WITH ;
>		Top = 168, ;
>		Left = 228, ;
>		Height = 36, ;
>		Width = 84, ;
>		Name = "Bcommandbutton1"
>
>	PROCEDURE bcommandbutton1.Click
>		#DEFINE dcEcho
>
>		WAIT WINDOW dcEcho
>	ENDPROC
>
>	PROCEDURE bcommandbutton1.Init
>		#DEFINE dcEcho "Test of dcEcho... define is in Init()"
>	ENDPROC
>
>ENDDEFINE
>
>
>When you run the form and click the button, the wait window echos the dcEcho that was defined in the Init(). If I commented out the #DEFINE dcEcho in the Click event, it errored out (no suprise there). If I put a legitimate string after the #DEFINE dcEcho in the click event, sometimes VFP would run the string from the Init() DEFINE, other times it would run the string from the Click() DEFINE.
>
>The VFP help says that #DEFINEs are only valid in the event/method in which they are "defined".
>
>I'm running VFP 6.
>
>Any ideas of what's going on?
>
>Regards,
>Thom C.
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform