Frans is right in the case you actually asked about -- the name of a local 
variable can't get you to a reference to the object whose reference is stored 
in that local variable.

However, in the context of a Windows Forms app (which I suspect is your 
situation given your use of a TextBox control in the example), you can examine 
the elements of the Controls array of the form, and check each to see if the 
Name property is what you want.  (You would need to do this recursively, as the 
control you're looking for could be "under" any of the form's controls.)

At 04:31 PM 6/29/2005, Frans Bouma wrote
>> Is there a way to get a reference to an object by its name?
>>
>> E.g.
>> TextBox st1 = new TextBox();
>>
>> Object o = GetObjectByInstanceName("st1");
>
>        No, if you want that, you should store the reference to the object in 
> a structure that's accessable by the code which wants
>to execute GetObjectByInstanceName.
>
>                Frans


J. Merrill / Analytical Software Corp

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to