[Gambas-user] how to write text in indexed list of labels

Benoît Minisini g4mba5 at gmail.com
Mon Sep 7 22:29:34 CEST 2020


Le 07/09/2020 à 21:41, Jussi Lahtinen a écrit :
> 
>     Look at it this way
>     Print TypeOf(Me["Label1"])
>     16  (=gb.Object)
>     OK! It is an object so I can do Object "stuff" with it. Like looking at
>     Object.Type
>     BUT if you read every word of the help for Object.Type
>     "Returns the class name of an object."
>     Object.Type(Me["Label1"]) is just rerturning a string which is the Name
>     of the class of which Me["Label1"] is an instance --- but it is
>     still an
>     object not a Label!
> 
> 
> I don't understand your point. That is exactly what I expect to see. 
> TypeOf returns "object" for every possible instance of every possible class.
> So, instance of Label is object and TypeOf will return so as expected.
> 
> The problem is that Me["Label1"] does not return an object, which is an 
> instance of class label, but instance of class control.
> That is unexpected. Looks like a bug to me.
> 
> 
> Jussi
> 

No, it's by design. ME[xxx] can return any subclass of the Control 
class, so it's logical that its datatype is Control.

If you know that ME[xxx] is a Label, then you have to store it into a 
variable declared as Label. Otherwise you can't access the Label class 
properties or methods.

Remember that the Object datatype is "anonymous". Each access to a 
property or a method through the Object datatype needs a search into the 
symbol table at each access, which is slow.

As soon as the interpreter gets an actual datatype (like Control for 
Form[xxx]), then the symbol table search is done once, and every 
following access is immediate, which is fast.

Regards,

-- 
Benoît Minisini


More information about the User mailing list