Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Local vs private
Message
De
12/08/2005 12:14:42
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
12/08/2005 11:39:17
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01039725
Message ID:
01040578
Vues:
23
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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform