user form property in a private data session form 
Author Message
 user form property in a private data session form

Hi all,
I used to use form property as a global variable, but the problem arise
in a private data session form. When I open more than one form
instances, the user defined property is 'shared' between forms.
Obviously, the result is not as expected to be.

Can anybody give me a suggestion? Do I practice a 'bad programming
habit' here? What's the alternatives? I don't like global variables
because it would be accessible in all forms. What i want is a variable
which is global inside all controls in the form and can be used in a
private data session.

TIA
Willianto



Fri, 06 Feb 2004 19:27:56 GMT  
 user form property in a private data session form

Quote:

> Do I practice a 'bad programming habit' here?

Yup 8-)

Quote:
> What i want is a variable
> which is global inside all controls in the form and can be used in a
> private data session.

With the best will in the world (might be "will-ianto" I suppose 8-))
there is (almost?) always at least one global variable.
Do you have an application object?  It's a good idea.  You can get to it
with a global variable, or (better?  more OOP?) create a reference to it
attached to each form.

In the application object put all the stuff (properties/methods) that is
application wide.

Regards
Mark
-If more of us acted more sensibly,
d'you think Governments might join in?



Fri, 06 Feb 2004 18:31:12 GMT  
 user form property in a private data session form
Have you tried adding  new property to the form. ?    That way, this form no
matter how many times it called, has the property  but you can assign it
different values for each instance.

In the form designer, click on form -> new property. give it a name. and
thats about it.   This might be what you are looking for.

Bob Lee


Quote:
> Hi all,
> I used to use form property as a global variable, but the problem arise
> in a private data session form. When I open more than one form
> instances, the user defined property is 'shared' between forms.
> Obviously, the result is not as expected to be.

> Can anybody give me a suggestion? Do I practice a 'bad programming
> habit' here? What's the alternatives? I don't like global variables
> because it would be accessible in all forms. What i want is a variable
> which is global inside all controls in the form and can be used in a
> private data session.

> TIA
> Willianto



Fri, 06 Feb 2004 19:46:59 GMT  
 user form property in a private data session form

says...

Quote:
> Hi all,
> I used to use form property as a global variable, but the problem arise
> in a private data session form. When I open more than one form
> instances, the user defined property is 'shared' between forms.

Not the value, though, right? Each instance of the form uses it's own
copy of the property. So, if you have 5 instances the property would
be, could be, different on each.

Quote:
> Obviously, the result is not as expected to be.

> Can anybody give me a suggestion? Do I practice a 'bad programming
> habit' here? What's the alternatives? I don't like global variables
> because it would be accessible in all forms. What i want is a variable
> which is global inside all controls in the form and can be used in a
> private data session.

Are you looking for the PROTECTED and HIDDEN keywords?  The following I
think will demonstrate what you're looking for. (The ELSE clause should
cause an error when another instance of the form tries to access the
first instance's properties).

LOCAL oform1

oform1=NEWOBJECT("form1")
oform1.SHOW

DEFINE CLASS form1 AS FORM

        DOCREATE = .T.
        CAPTION = "Form1"
        WINDOWTYPE = 1
        HIDDEN MyHidden
        MyHidden = "Hidden"
        PROTECTED MyProtected
        MyProtected = "Protected"

        NAME = "Form1"

        ADD OBJECT textbox1 AS TEXTBOX WITH ;
                NAME = "textbox1"

        ADD OBJECT textbox2 AS TEXTBOX WITH ;
                TOP = 30, ;
                NAME = "textbox2"

        ADD OBJECT Command1 AS COMMANDBUTTON WITH ;
                TOP = 60

        PROCEDURE INIT(toForm)
                IF VARTYPE( toForm ) <> "O"
                        THIS.textbox1.VALUE = THIS.MyHidden
                        THIS.textbox2.VALUE = THIS.MyProtected
                ELSE
                        THIS.textbox1.VALUE = toForm.MyHidden
                        THIS.textbox2.VALUE = toForm.MyProtected
                ENDIF
        ENDPROC

        PROCEDURE Command1.CLICK
                LOCAL oform1

        oform1=NEWOBJECT("form1", "temp.prg", .NULL., THIS.PARENT )
                oform1.SHOW

        ENDPROC

ENDDEFINE
*
*-- EndDefine: form1
**************************************************



Sat, 07 Feb 2004 02:21:54 GMT  
 user form property in a private data session form
Thanks all-
you've been very helpful :)



Quote:
> says...
> > Hi all,
> > I used to use form property as a global variable, but the problem
arise
> > in a private data session form. When I open more than one form
> > instances, the user defined property is 'shared' between forms.

> Not the value, though, right? Each instance of the form uses it's own
> copy of the property. So, if you have 5 instances the property would
> be, could be, different on each.

> > Obviously, the result is not as expected to be.

> > Can anybody give me a suggestion? Do I practice a 'bad programming
> > habit' here? What's the alternatives? I don't like global variables
> > because it would be accessible in all forms. What i want is a
variable
> > which is global inside all controls in the form and can be used in a
> > private data session.

> Are you looking for the PROTECTED and HIDDEN keywords?  The following
I
> think will demonstrate what you're looking for. (The ELSE clause
should
> cause an error when another instance of the form tries to access the
> first instance's properties).

> LOCAL oform1

> oform1=NEWOBJECT("form1")
> oform1.SHOW

> DEFINE CLASS form1 AS FORM

> DOCREATE = .T.
> CAPTION = "Form1"
> WINDOWTYPE = 1
> HIDDEN MyHidden
> MyHidden = "Hidden"
> PROTECTED MyProtected
> MyProtected = "Protected"

> NAME = "Form1"

> ADD OBJECT textbox1 AS TEXTBOX WITH ;
> NAME = "textbox1"

> ADD OBJECT textbox2 AS TEXTBOX WITH ;
> TOP = 30, ;
> NAME = "textbox2"

> ADD OBJECT Command1 AS COMMANDBUTTON WITH ;
> TOP = 60

> PROCEDURE INIT(toForm)
> IF VARTYPE( toForm ) <> "O"
> THIS.textbox1.VALUE = THIS.MyHidden
> THIS.textbox2.VALUE = THIS.MyProtected
> ELSE
> THIS.textbox1.VALUE = toForm.MyHidden
> THIS.textbox2.VALUE = toForm.MyProtected
> ENDIF
> ENDPROC

> PROCEDURE Command1.CLICK
> LOCAL oform1

> oform1=NEWOBJECT("form1", "temp.prg", .NULL., THIS.PARENT )
> oform1.SHOW

> ENDPROC

> ENDDEFINE
> *
> *-- EndDefine: form1
> **************************************************



Sat, 07 Feb 2004 21:44:14 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Form's Private Data Session working with OLE to Excel

2. Multiple forms w/ private data sessions, and performance

3. How to access Private Data Session Form DataEnvironment

4. Multiple Forms, Private Data Sessions

5. Setting form's PRIVATE DATA SESSION ?

6. Determining Cursor Objects in Forms with private data sessions

7. Sharing tables in forms with private data session

8. private data sessions too private?

9. Opening a form in another form's data session

10. Disappearing data in a Private Data Session

11. Forms Created with Addobject method not have private session

12. VFP 5.0 Form,Data Environment, Data Session

 

 
Powered by phpBB® Forum Software