[Gambas-user] Gambas Help - PLEASE - Object Arrays - Need help ASAP

Doriano Blengino doriano.blengino at ...1909...
Thu Nov 6 21:36:00 CET 2008


Rob ha scritto:
> On Thursday 06 November 2008 13:37, Doriano Blengino wrote:
>   
>> i.e., LAST is a reference to the object that raised the event, and you
>> can compare it to anything you like (probably widgets).
>>     
>
> Yes, that should work, but with limitations.  You would have to hardcode 
> the name of the control you wish to compare against at compile time.  
> Gambas lacks enough introspection at present to obtain a reference to an 
> object using its symbol name at run time.  (As far as I know, the same is 
> true of VB.)
>   
Gambas does not lack introspection. You can compare LAST.name to a 
string, or LAST to a variable (an instance variable), or even look at 
the type of the object (object.Type(LAST)). The symbol name is a 
reference to the object,
Mainly, my thought was directed to groups of widgets created at design 
time, where the name (symbol) of the widget/control *is* a reference to 
the object.

>> The tag system is another way - sometimes tags are better, sometimes
>> control/widget reference is.
>>     
>
> Agreed.  This will be easier if you have "OK" and "Cancel" buttons across 
> the bottom of the screen and want to tell which one got pressed, but if 
> you have an array of 64 buttons (or text boxes, like one of my clients) it 
> might be time to start assigning tags at control creation.
>   
If you have a true array, then LAST = btns[0] should work. If you don't 
have an array (ie: for i=0 to 10 bnt = new Button....), then you don't 
have any reference to the objects you created, so clearly you can't 
compare to a reference you don't have...
But note that you don't have to use Tag - you could use Name, Left, or 
whatever differentiates these controls each other. Of course, Tag is 
devoted to such things.

Regards,
Doriano







More information about the User mailing list