1

Konu: Code order

Hello:

One thing is nagging at me. In code that Cetin helped me with, I have

PUBLIC oForm

oForm = CREATEOBJECT('MainMenu')

oForm.Show()

*

DEFINE CLASS MainMenu AS Form

    Height = 900
...

ENDDEFINE

Here, a form (oForm) base on a class (MainMenu) is created before the class. Often, in VFP, a name that is invoked before it exists means that VFP crashes. Not so here; this works. How come?

But, logically, even if this does work, should it not be

DEFINE CLASS MainMenu AS Form

    Height = 900
...

ENDDEFINE

*

PUBLIC oForm

oForm = CREATEOBJECT('MainMenu')

oForm.Show()

?

Regards,

Hans L

2 Son düzenleyen, cetinbasoz (14.09.2010 22:34:25)

Re: Code order

Hans,
Within the syntax rules of VFP, if there is one or more class definitions, then those definitions should appear last in code. In other words this is the right way to do it:

Visual Fox Pro
* any code

 
define class ...
* ...
enddefine
 
* another class if any
define class ....
* ...
enddefine


With code like:

Visual Fox Pro
oForm = createobject("MainMenu")

VFP would search for a class definition of mainmenu within the same code or in one of the open procedure files. You can keep your class defintions in one file and explicitly call from there using newobject(). ie:

Visual Fox Pro
oForm= NewObject("mainmenu", "c:\MyFolder\MyFormClasses.prg")

3

Re: Code order

Thanks for clearing that up for me, Cetin.

Regards,

Hans L