Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Referencing a class in a form from another class
Message
 
To
06/08/1997 16:26:04
Edward Crawford
City Facilities Management
Glasgow, United Kingdom
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00043412
Message ID:
00043844
Views:
34
>I have a class that is made up of a container and some labels. We will call it Example1.
>
>I instantiate this class with oExample1 = CREATEOBJECT("example1") at the beginning of my program. I then run a form with DO FORM. In the ini() method of the form, I ADDOBJECT("oExample1", "example1") this container class to the form.
>
>While the program is running, a timer object fires a method in another class that was also instantiated at the beginning of the program with oExample2 = CREATEOBJECT("Example2"). While this method is running, it updates the captions in the first class with oExample1.lblLabel.Caption = Testing". This update is not reflected in the Example1 class.
>
>My thought is that I have create two separate instances of Example1, so changeing the labels in oExample does not effect frmForm.oExample. If this is true, how do I go about writing to the object in the form from outside the form. I have tried _SCREEN.frmForm.oExample, frmForm.oExample, and _VFP.frmForm.oExample to no avail. The other question would be, am I going about this the wrong way?
>
>Thanks Ed
Ed,

You are correct that you are manipulating the wrong instance of your class. To manipulate the object inside of the fomr you need to address it there. You can use;

_screen.ActiveForm.oExample1

if the form is the currently active form. Beyond that you would need some kind mechanism for tracking the fomrs that have been launched.

The other issue is that you are confusing the Name property of the form with the form object's name, they are not the same thing. To assign a name to the form object you need to use the NAME clause on teh DO FORM command, as in;

DO FORM MyForm NAME MyForm LINKED

the LINKED keeps the variable holding the form reference (MyForm) existance as long as the form is there.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform