Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
(Formnamehere) vs. Thisform
Message
De
15/09/2011 11:12:37
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
14/09/2011 11:56:36
Kevin Hickman
The Cadle Company
Ohio, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Novell 6.x
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01523519
Message ID:
01523627
Vues:
98
>One of my forms all of a sudden does not understand it's reference to the name. I get an error that the (formname) does not exiist. Clearly the form is loaded in on screen in the background. If I change the reference to thisform.object it recognises it until it runs into the next one with formname.object. I could rename all code on the form to be thisform, but certain areas like the main prg and other parts do not allow use of thisform to reference, you must use the name of the object. In the debugger screen I put in thisform.name and it shows the name of form on the screen which is correct, if I put in thisform.objectname it shows me it in the list as an object, but if I put FORMNAME.object I will see "Expression could not be evaluated". How can it say the name of the currect form is that, but can not reference it by that name anymore. Can anyone explain to me how this happens and how I can correct it?

Thisform is a guaranteed object reference that will point to the object even if the object is not quite built yet, i.e. even before .load() finishes.

Any reference to the form, like something you can stuff in a variable and call it, has to be assigned to that variable first. I don't know how you got that working from within the form in the first place, probably by only using it in code which runs _after_ the form finished instantiating, having a variable that Fox will create anyway if you don't (something has to hold the reference to the object), and having only one instance of the form. IOW, you were lucky.

When you instantiate a form class, or run a form and assign it to a variable, by one of these
do form myform name loMyFormRef
myFormRef=createobject("myformClass")
the variable myFormRef is not assigned a value until the form's .init() finishes. Officially, it doesn't exist yet, so any variable that you want to assign its value to will not have that value, not yet. You may try to gamble with a variable initialized before instantiating a form, then have
myOutsideVariable=thisform
somewhere in form's code, but that would prevent you from ever running two instances of the form (or if you run the 2nd you'd lose the reference to 1st), and would mark you as a dirty programmer :). IOW, that's unreliable, doesn't scale, and is not good for your nerves.

So, inside the form's code, use Thisform always. Any other way to reference it is not guaranteed - the reference may not exist yet, or may not exist anymore if it's somewhere in the .destroy() or .unload(). Also, your code wouldn't work on its own because it relies on an outside reference, and that breaks your encapsulation.

A final note: what do you mean "(formnamehere)"? If it's thisform.name - well, that's just a string assigned to the name property and can be changed at will during runtime (you can even do thisform.name="blabla", and as long as the string contains a valid name, unique within parent's objects, it will be accepted). I just assumed you meant a variable, but maybe I misread.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform