Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How Do I? Object Reference for a Form
Message
 
 
À
25/08/2005 01:55:27
Donald Lowrey
Data Technology Corporation
Las Vegas, Nevada, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01043708
Message ID:
01043882
Vues:
9
Del,

The reason this works at dev time is because you are doing it from the command window right? When you do that DO FORM XYZ will create a memvar named XYZ that has a lifetime tied to the VFP session. In a PRG DO FORM XYZ creates a memvar XYZ that only lives until the routine ends.

It's bad to write code that depends on these memvar names because of the problems you've had. Creating public memvars as others have suggested makes it impossible to run more than one instance of your form.

If the second modal form is really spposed to interact with the first form you could launch it from the first form and pass thisform to it, that way the modal form has an object reference it can use. If you are going to launch the modal form from a menu you should use the _screen.Forms[] collection to find the first form, or use a form manager object. But what if you have two instances of the modeless for running? Which one does the modal form want to talk to?

>Good evening all
>
>How do I get a global object reference to a form called by a prg file?
>
>I have a modless form (form1) that is called from a prg via DO FORM form1. Another form (form2)is modal and is called by a menu snipet. Form2 runs some code to change a few properties in Form1. Sounds simple enough, and in fact when running this in my development environment it works fine.
>
>BUT, when running my app, The below code fails.
>
>**form2.mycusmeth()
>form1.backcolor = RGB(255,255,255)
>* fails, error "form1 is not an object"
>
>
>I know that the error is caused by Form1 going out of scope, because it was called from a prg. To remedy, I ran the following in the prg file calling form1.
>
>** prg calling form1
>PUBLIC form1 AS Object
>form1 = .f.
>DO FORM "form1.scx" NAME form1
>
>
>Running the form2.mycusmeth() code still throws the same error, "form1 is not an object".
>
>So, Fox gurus, lend me your genius. How to I obtain and retain an object reference to form1?
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform