Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Objects and Variables in a Form
Message
De
11/12/1998 09:20:07
Andy Roth
Neyenesch Printers
Californie, États-Unis
 
 
À
11/12/1998 07:52:11
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00165931
Message ID:
00166524
Vues:
11
>>>>Are all objects in a form PRIVATE by nature even if their
>>>>name is the same as a public object or variable?
>>>>
>>>>I know all variables in a program or procedure are
>>>>private unless they are the same name as a public one.
>>>>In that case you need to declare the varible as PRIVATE.
>>>>
>>>>How do you declare an object in a form as private?
>>>>can you declare all objects at once in the form as private?
>>>
>>>
>>>To understand the nature of your question, it is necessary to understand what happens when an object is created. The general syntax of an object is;
>>>
>>>Public (or Private) NewObjectName
>>>NewObjectName = CreateObject("ParentClass")
>>>
>>>The scope of the object is dependant on whether the object is declared as public or private. I would recommend avoiding public objects that only have function or use within a particular form or method.
>>>
>>>Public objects are great for error handling, data access, things like that that will be needed throughout the application.
>>>
>>>Just a thought or two on the subject.
>>>
>>>Regards,
>>>
>>>Jason
>>
>>What would be the default scope of a form and it's objects contained within?
>Andy,
>You CCed this to me so want my 2 cents opinion too ?
>I don't agree declaration as private would make a form (or another object private).
>* Code segment
>private myform
>myform = createobject("form")
>myform.comments = "I'm private. You cannot access to me."
>myform.show
>return
>
>* After return myform doesn't provide access to form - right
>* Form is private - wrong
>All made private is "myform" object ref variable not the form object.
>Any objects created in a VFP session are members of some container. This means any object created can be accessed from any level provided it still exists.
>* Now the form is running and "myform" was private
>* A simple call
>_screen.setall("New caption","Caption","Form")
>would also set "myform".caption.
>This at least shows you can access to it.
>Let's change caption of *unacessible* "myform" :
>
for each oForm in _screen.forms
>    if oForm.comments = "I'm private. You cannot access to me."
>       oForm.caption = "You think so :)"
>       exit
>    endif
>endfor
If you really "blackbox" most of available objects (for simplicity say for those objects that you could get into a container object) use "control" object. A control object is like a container object but prevents access and manipulation of its contained objects at design time + runtime. OTOH it's not as easy to deal with a control object as like a form or container object and you cannot use ie: addobject with it.
>Another kind of "privacy" could be obtained by a modal form. At runtime using a modal form + limiting access to menu item (ie: via skipfor) provides a virtual "privacy". And IMHO this one is closer to "private" for variables.
>If what you think of is just to prevent accidental of changing values for ie:textbox objects in a form then keep cool, every object in a form are totally different from objects on another form with same name and again same name object. ie : You have a form named customer.scx with txtCustName in it and at designtime you changed the form.name to frmCustomer :
>
* Launch the form 3 times
>do form customer
>do form customer
>do form customer
>activate screen
>? frmCustomer.txtCustName.value && error
>? _screen.frmCustomer.txtCustName.value && error
>? customer.txtCustName.value    && Would print correct - might be just empty for the moment
>* Now check where does customer.txtCustName refer
>customer.txtCustName.value = "cetin"
>customer.refresh  && Only last called form changes
>* Because form scx name is "customer.scx" this works with the last activated
>* Go and close last activated
>customer.txtCustName.value = "cetin"  && Error - customer is not an object
><pre>for ix=1 to _screen.formcount
> _screen.forms(ix).txtCustomer.value = "cetin"+padl(ix,2,"0")
> ? _screen.forms(ix).name    && All prints "txtCustomer"
>* But obvious you can't refer them as _screen.txtCustomer
>* or just txtCustomer
>endfor
They change value separately (each txtCustomer is "private" to its container - form).
>This is demonstrated in a better way in home()+"samples\solution\solution.app". Check for "Forms\Run multipl instances of a form".
>Cetin

Thanks
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform