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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can u reference an object by a relative reference? 2

Status
Not open for further replies.

Raccoon

Programmer
Aug 18, 1999
92
US
You can reference the current object by:

THIS.property

and by absolute by:

THISFORM.pgfMain.pagCharts.pgfCharts.pagChartLookup.cmdMyCommand.property

Is there a way to reference that object similar to a relative reference such as:

...cmdMyComand.property

from another object on pagChartLookup ?

 
Yes, but it's not recommended.

if THIS is an object on a page in a pageframe, and Text1 is another object on the same page:

THIS.Parent.Text1.Caption = "Whatever"

if Text1 is on a different page:
THIS.Parent.Parent.Page3.Text1.Caption = "Whatever"

However, it's really not recommended to do this: The only case I'd say you should do this would be in a class that you want to re-use in different forms. Otherwise, I usually create a method on the form, ShowCalcValues, that I call from anywhere when the values should be updated: "THISFORM.ShowCalcValues". This way you only have to look in one spot (the form Itself) to find where they are set instead of searching through all the contained objects' events.
 
Thanks,

You are correct in all respects. In this particular situation, I have multiple objects in a container that I re-use from one page frame to another. So, the This.Parent. is the answer. However, I also have objects that only exist in one location, and are not re-used elsewhere. I already use the THISFORM.ShowCalcValues method for them and it works really great. Only one place to make changes, etc..

Thanks very much

Mike
 
You can also create a method that tries to retrieve an object reference to an object with specific properties.
Use PEMSTATUS and the controls[] and controlcount properties of the objects.

So if you know the specific properties of an object, you can retrieve a reference from anywhere on you form by searching through the objects on that form using a drilldown methodology.

In this way, the only parameters to use are the specific properties that identify you control c.q. object.

HTH,
Weedz (Edward W.F. Veld)
My private project:Download the CrownBase source code !!
 
Why not set a property, or a regional / public variable to the object, e.g.

public bob

bob = thisform.pageframe1.textbox1 (for example)

then to set values from anywhere in the program, if bob is public,or you could have a system object where bob is property , you could do:

bob.value = 'hi'

or in the latter case

osystemObject.bob.value = 'hi'

basically, all that is in bob is a pointer to the actual object.

Notes: the object you want to reference in this way has to be instantiated, and, to release the form, you will have to release bob first, or set it to null, because the form will not exit if there are active object references.

Hope this helps

Simon

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top