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

object reference with variables?

Status
Not open for further replies.

AlastairOz

Technical User
Jul 27, 2010
81
0
0
AU
Can I use variables to create an object reference,
for instance:

thisform.textbox1.visible=.t.

can I use a variable for the "textbox1" part?

thisform.variable.visible=.t.

or

thisform.textbox + variable.visible=.t.

I have 252 objects on a form that I wish to vary the properties for, without doing a very big CASE/ENDCASE.




 
Alastair,


use EVALUATE

something like...

for i=1 to 200
lobject = evaluate("thisform.mytextbox"+transform(i))
lobject.visible = .t.
next


nigel



 
You can use this:
Code:
lcVar = "text1"
thisform.&lcVar..visible=.t.
The two dots is not a typo, it is required.



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Also take a look at SetAll():

Thisform.Setall("visible",.t.,"textbox")
sets all textboxes visible. And the last parameter is optional, skipping it sets all controls visible.

Changing "textbox" to "mytextbox" will only affects a class "mytextbox", you may have created and used instead of the base class textbox. Actually this is a thing strongly rcommended.

Because if you need to give any functionality or even only look (font, fontsize) to ALL of your forms, then a class is the best place to change that, as it even does not require SetAll. You simply change the classes font and everywhere throughout the project the font will change without any further code, not even setall().

I wonder also, if you actually couldn't redo that form to have a few grids instead of several groups of controls. It's much easier to maintain, than a series of controls.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top