accessing dfl objects

Christian Hartung christian.s77 at gmail.com
Thu May 8 06:52:47 PDT 2008


Tyro[a.c.edwards] escreveu:
> Milke Wey Wrote:
> 
>> On Mon, 2008-05-05 at 23:35 -0400, Tyro[a.c.edwards] wrote:
> 
> [snip]
> 
>>> I've found that if I instantiate each TextBox at class scope, then I can access and update them later, however, since there will literally be hundreds of these boxes I don't want to have to declare a pointer to every single one. Is there another way?
>>>
>>> Any assistance is greatly appreciated.
>>> Andrew
>> I don't use DFL myself but looking at the on-line documentation
>> something like this should do it.
>>
>> foreach(ctrl; control.controls)
>> {
>> 	´╗┐TextBox textBox = cast(´╗┐TextBox)ctrl;
>>
>> 	if ( textBox !is null )
>> 	{
>> 		//Do something with the text box
>> 	}
>> }
>>
>> -- 
>> Mike Wey
>>
> 
> Thanks for the assistance Mike... This works great if I'm trying to access the control itself, but in this case I'm trying to get to the objects embeded in the control.
> 
> For example: I have a tabbed control with 7 tabs and each tab has a set of labels, buttons, and textboxes. This method allows me to access the properties of the tabbed control but I'm trying to find out how to access the textboxes on each tab.
> 
> Thanks again,
> Andrew

I think this should work:

foreach(c; control.controls)
{
     TabPage t = cast(TabPage)c;

     if(t !is null)
     {
         foreach(ctrl; t)
         {
             TextBox textBox = cast(TextBox)ctrl;

             if(textBox !is null)
             {
                 // ....
             }
         }
      }
}


More information about the Digitalmars-d-learn mailing list