Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Local vs private
Message
De
12/08/2005 13:02:47
 
 
À
12/08/2005 12:14:42
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01039725
Message ID:
01040582
Vues:
19
Thanks Cetin and Craig -
My understanding is slowly growing.
btw - I found and Advisor tip from March 2002 that speaks to the subject of form references. It suggests the following line in a form's load or init event will grab a reference to the calling form without further fuss.

if type('_screen.activeform') = 'O' and not isnull(_screen.ActiveForm)
this.oParent = _screen.ActiveForm
endif

I tried it and it seems to work well.
Thanks again.

>Don,
>Believe me I thought sooner or later this subject would turn into this:)
>Private variable is visible to any routine down from where it's declared. IOW consider you have
>funcA, funcB, funcC, funcD each calling one another in chain and funcX called separately.
>
>
>public m.var
>m.var = "hello"
>? "Main",m.var
>funcA()
>? "funcA return",m.var
>funcX()
>? "funcX return",m.var
>
>procedure funcA
>private m.var
>m.var = "there"
>funcB()
>? "funcA", m.var
>
>procedure funcB
>m.var = "again"
>funcC()
>
>procedure funcC
>m.var = "from"
>funcD()
>
>procedure funcD
>m.var = "VFP"
>
>procedure funcX
>m.var = "funcX"
>
>However with object methods (like form.load, init etc) things are different. You do not call them in chain from within another. IOW:
>
>
>m.var = 'hello' && public, private whatever except local
>do form myForm
>
>This is a chain call, any method in myForm sees m.var and can change it. This one is not a chain call (consider m.var is not defined before a call to do form somewhere in chain):
>
>*myForm.load
>m.var = "hello"
>* here as soon as load routine ends m.var goes out of scope
>
>*myForm.init
>messagebox(m.var) && error - m.var is not defined
>
>
>Make it visible to all form members:
>
>*myForm.load
>this.addproperty('var',"hello")
>* Now it's a form property - any object that can access thisform sees it
>
>*myForm.init
>messagebox(this.var) && OK
>
>
>In your case actually button click doesn't even see your PRIVATE frmSwitchBoard variable (try changing its name). By coincidence it works (not exactly coincidence).
>
>frmSwitchboard.visible = .f. && This doesn't error
>do form frmForm2
>
>Try completely removing:
>
>private frmSwitchboard
>frmSwitchboard = thisform
>
>from load. It would still run w/o error. To understand why invoke the debugger and check (depending on how you instantiate a form you get a variable pointing to that form. ie:
>
>do form myForm.scx
>do form myForm.scx
>do form myForm.scx
>myForm.Caption = "Hello" && scx's name points to first instance in stack
>? _vfp.forms[1].caption
>
>To keep long story short keep your switchboard's reference in public oApp (that you create in main.prg). ie:
>
>
public oApp
>oApp = newobject('custom') && Ideally it would be NewObject('myApp','myApp.prg') or similar
>*... some code
>oApp.AddProperty('SwitchBoard')
>do form mySwitchBoard NAME oApp.SwitchBoard
>read events
Now application wide you could access your SwitchBoard form like:
>
>oApp.SwitchBoard.Hide()
>oApp.SwitchBoard.Show()
>etc.
>
>Cetin
>
>
>>Thanks to all of you who have shared thoughts on this subject. I gave it a try in my current application and this is what I found. In the load event of my first form I place:
>>
>>private frmSwitchboard
>>frmSwitchboard = thisform
>>
>>Then in a button on frmSwitchboard I place
>>
>>frmSwitchboard.visible = .f.
>>do form frmForm2
>>
>>In the destroy event of frmForm2 I place
>>
>>frmSwitchboard.visible = .t.
>>
>>At this point I get an error that effectively says it can't see frmSwitchboard. Now if frmForm2 was called by frmSwitchboard, why can't frmForm2 see it?
>>
>>Incidentally, if I replace the PRIVATE statement with a PUBLIC one, the problem goes away.
>>
>>- Don
>>
>>>>Hi,
>>>>
>>>>>>I don't use any PUBLIC variables. In my Main.prg, I create a PRIVATE var,
>>>>
>>>>So what's the difference between a PUBLIC var and a var declared as PRIVATE at the top level ?
>>>>
>>>>Regards,
>>>>Viv
>>>
>>>One difference comes to mind - goApp loses being immune to "release all" command if declared as PRIVATE. ie:
>>>
>>>*Main1.prg
>>>PRIVATE goApp
>>>*...
>>>
>>>*Some procedure
>>>release all && goApp is released - wouldn't if declared as PUBLIC w/o extended clause
>>>
>>>IOW I'm with you. I declare it as PUBLIC if not using Application object instead.
>>>Cetin
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform