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

Object name 'Full Path'

Status
Not open for further replies.

SimplyES

Programmer
Oct 5, 2012
39
GB
I have a simple reusable class which is used as a Form method and accessed by multiple objects on a form, including those on pageframe pages. I pass the object's controlSource and it's data table name to the method. I would like to pass the object name, too, which I can do using this.Name, of course. However, if the object is on a page, the method (at form level) cannot correctly use the object Name as passed. I am currently passing the Name to the method in longhand (thisform.pageframeName.PageX.ObjectName) each time. Is there a way of achieving this by reference instead, without the long winded 'this.parent.parent + "." + this.parent + "." ... etc and without the whole thing falling over if I don't include the right number of levels?
 
Instead of passing this.name, pass This -- in other words an object reference to the control itself. It's probably all you'll need because all of the other values you're passing can be deduced if you have a reference to the object itself.
 
I agree with Dan.
On the other hand, you can use SYS(1272, This) to achieve what you asked for.

Code:
PUBLIC ofrm
ofrm = CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS MyForm as Form
	ADD OBJECT pg as pageframe WITH pagecount = 2
	PROCEDURE init
		This.pg.page1.addobject("text1","mytextbox")
		This.pg.page1.text1.visible = .T.
	ENDPROC
	PROCEDURE mymeth
		LPARAMETERS tcName,tcHier
		MESSAGEBOX(tcName)
		MESSAGEBOX(tcHier)
	ENDPROC
ENDDEFINE
DEFINE CLASS mytextbox as TextBox
	PROCEDURE click
		ThisForm.mymeth(This.Name,SYS(1272, This))
	ENDPROC
ENDDEFINE

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Besides working with the reference THIS also take a look at the form.OBJECTS array, you can iterate it, if you'd do something on each control.

Also take a look at the form.SETALL() method, it can set a property common to all controls, you can limit it to a certain control class or base class and if you define an proeprty_assign method you may individually react to the setting of a value within each control class. It's the classical thing to do, if you eg want to let any label of a form translate to another language.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top