>Hi all,
>
>I wanted to write some generic code that would continue to work even if I added objects to a screen at runtime.
>
>Is there another way to get an object reference to a screen object when part of the name is in a var?
>
>I know I can use PEMSTATUS() to test if the object exists. Say that below was in a loop to test for a dozen objects
>
>lnLoop = 5
>
>lcObjectName = "label" + LTRIM(STR(lnLoop))
>
>IF PEMSTATUS(THISFORM,lcObjectName,5)
>
> loLabel = THISFORM.&lcObjectName
>
>ENDIF
>
>Is there any other way to get a reference to the object other than macro expansion? I think I figured this out once but dang if I can find it.
>
>Thanks,
>Albert
For matter of argument, a good way to handle these kind of situations is registering the objects using a collection object. For this to work you add a collection object to the form and add the object references (at the time when you create the labels on the form, and you have a reference to that label object:
THISFORM.oLabels.Add(loLabel)
Then later at any time you just go through that collection to do certain operations, and now you can do that completely anonymous without knowing how many labels there are:
LOCAL loLable AS Label
FOR EACH loLable IN THISFORM.oLabels FOXOBJECT
IF loLable.Visible = .F.
loLable.Visible = .T.
ENDIF
ENDFOR
You can also write a method to return a sub collection based on certain criteria and do the operations on the subset.
Christian Isberner
Software Consultant