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

Bruce adamnt42 at gmail.com
Mon Sep 7 19:02:47 CEST 2020


On 7/9/20 11:21 pm, Jussi Lahtinen wrote:
> That's weird... if you try it with simple form and a label, this prints:
> Print Object.Type(Me["Label1"])
> Label
> 
> But when you try to use it, it's control... I don't think there should be a
> cast to other types.
> Benoit?
> 
> 
> Jussi
> 
> 
> 
> On Mon, Sep 7, 2020 at 4:27 PM Gianluigi <bagonergi at gmail.com> wrote:
> 
>>
>>
>> Il giorno lun 7 set 2020 alle ore 14:45 Jussi Lahtinen <
>> jussi.lahtinen at gmail.com> ha scritto:
>>
>>> No, I meant:
>>> Me["Label" & $iIndex].Text = "Pippo"
>>>
>>
>> mmmh, have you tried it, does it work?
>> I get: Unknown symbol Text in class Control
>>
>> Regards
>> Gianluigi
>>
>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>>
> 
> 
> 
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
> 

This one I do know! I have fallen for the same trap many times.

Me["somename"] returns an object that "looks" like a Control, but it's 
not its an Object, which doesn't have a "Text" property.
You do have to assign it to a Control (or a specific control type) in 
order to get the properties expected.

Dim hLbl As Label

hLbl=Me["label" & $iIndex]
hLbl.Text ="Pippo"

BTW It is wonderful that this is so! As it enables us to write hundreds 
of custom controls which may have any number of weird properties unknown 
to Me[controlname As String]

I will amend the help.

cheers
bruce


More information about the User mailing list