Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Private variables and forms

Status
Not open for further replies.

fitedgar

MIS
Apr 24, 2002
238
US
I have a program :

Private lc_dummy
lc_dummy = "Hello"
DO FORM TESTFORM
READ EVENTS

The form does not recognize the variable lc_dummy.
I thought private variables are seen below the main program
where it is created. The code above works with:
PUBLIC lc_dummy

Thank you
EMC
 
From the MSDN:

"
Remarks
Items within VarList are separated by commas. The hiding of variables created in higher-level programs enables variables of the same name as the private variables to be manipulated in the current program without affecting the values of the hidden variables. Once the program containing PRIVATE has completed execution, all variables and arrays that were declared private are again available.

PRIVATE doesn't create variables; it simply hides variables declared in higher-level programs from the current program.
"
Dave S.
 
EMC,
What version and SP of VFP are you seeing this in? Is the form top-level or modal? Does the form use a Private Datasession?

Rick
 
Thank you for your response:
RGBEAN:
The form is modal and uses private DataSession.
 
If you issue do form ... you are instantiating an object.
Private variables are scoped to the current procedures and procedures called from the current procedure.

Since an object can also be parsed and referenced to totally other functions cq object methods, it wouldn't make much sense to also scope that private to objects' methods.

Values to objects should be passed using parameters of object properties.

HTH,



Weedz (Edward W.F. Veld)
My private project:Download the CrownBase source code !!
 
Hej !
try:
Private lc_dummy
lc_dummy = "Hello"
DO FORM TESTFORM with lc_dummy
READ EVENTS

in the form create new property, eg 'nowa_prop'

at form.init
LPARAMETERS lc_dummy
nowa_prop=lcdummy

and this property is for whole form
Kind regards from Warsaw !!!!!
Monika (monikai@yahoo.com)
 
HI,
1. Private variables shall be available in the called form.
2. Monikai's suggestion will work, but it doesnt explain the reason for not making the variable available.

I have used, PRIVATE and it is available in all the called forms.

****************************************
PUBLIC oform1
PRIVATE pc_dummy

pc_dummy = "My Private pc_dummy"
oform1=NEWOBJECT("form1")
oform1.Show()
RETURN

DEFINE CLASS form1 AS form
DoCreate = .T.
Name = "form1"
PROCEDURE Activate
WAIT WINDOW pc_dummy
ENDPROC
ADD OBJECT command1 AS commandbutton WITH ;
Top = 10, ;
Left = 5, ;
Height = 27, ;
Width = 84, ;
Caption = "Exit", ;
Name = "Command1"
PROCEDURE command1.click
thisform.Release()
ENDPROC
ENDDEFINE
*****************************************
:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
ramani,
I agree with you - it should be available. I added these two statements to your form Class definition, and they didn't change the result (as I had thought possible).
Code:
    DataSession = 2 && Private
    WindowType = 1 && Modal
EMC,
You must be declaring a variable somewhere that is "hiding" the PRIVATE declared in your main program. Using the debugger, stop where it's not found, and then walk the stack backwards checking the "Locals" window for where it disappears.

Rick
 
Thank you very much for your kind attention.
I have resolved the above problem by
changing the property of the form
"show window" : 0 In Screen ( as default)
This works.
IF I use "show window" properties 1 In top level form or
2 as top level form, the variable is not seen within the form.
EMC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top