>i have a main form and have commnad buttons on that form that use, mainform.visible = .F., in the load
>event of the second form and the, mainform.visible = .T., in the unload event of the form. this works find if
>im working in the project, but once i compile the project and try to run this i get the message ,
>"object mainform is not found". i cant understand it since it works when im testing it but doesnt work
>from within the .exe file. i've checked syntax and recompiled the project to no avail.
Rather than assuming that the form is directly addressible by an object variable 'mainform', why not pass a direct object reference in and save it, so that the object reference remains constant?
Create a form property in the second form called 'oPrevForm'. Add the following code to your second form's Init:
LPARAMETER oFormRef
thisform.oPrevForm = oFormRef
replace all occurances of 'mainform.' in all of your second form's code with 'thisform.oPrevForm.'
When starting the second form from the first form, change the DO FORM to read:
DO FORM
second form WITH thisform
This does a number of useful things. First, it gives you a reference that is independent of the name of the calling form. If some time in the future there's a need to rename the first form, you needn't change the second as well.
Second, if you want to call it from another form, you can use the same second form - you don't need a separate copy to call it from a form named "masterform".
Third, it keeps the object reference constant in the scope of the form you need not worry about side-effects hiding the object reference, for example, if you use the current mechanism, you'd lose the ability to reference mainform in any function or method that contained the statement:
LOCAL mainform
or worse:
PRIVATE ALL LIKE main*
You can also test to make sure that the object reference is valid and still alive - if somehow mainform terminated while the second form were running, you could discover this by checking ISNULL(thisform.oPrevForm)
If none of this makes sense, you can also use the NAME clause in the first DO FORM to ensure that a variable named mainform is created with a private context; in the long run, the other approach offers significant advantages