[Gambas-user] refer to an object with a string
Jean-Yves F. Barbier
12ukwn at ...626...
Sun Aug 16 18:38:53 CEST 2009
Doriano Blengino a écrit :
> Jean-Yves F. Barbier ha scritto:
>> Hi list,
>>
>> I'm trying to refer to come couples Label/CheckBox that have the same suffix
>> (lbl_ONE & ckb_ONE) to enable/disable couple in one shot.
>>
>> But after building my strings that are orders, GB tell me its not an object:
>>
>> PUBLIC SUB lblckb_on_off(which AS String, on AS Boolean)
>> DIM lbl AS String
>> DIM ckb AS String
>>
>> lbl = "lbl_" & which & ".Enabled = "
>> ckb = "ckb_" & which & ".Enabled = "
>> IF onoff THEN ' ON
>> lbl &= "TRUE"
>> ckb &= "TRUE"
>> (SOMETHING TO "EXEC" THE STRING)lbl (or may be: (SOMETHING)lbl = TRUE)
>> (SOMETHING TO "EXEC" THE STRING)ckb
>> ENDIF
>> END
>>
>> Is there a way to do that?
>>
> The EVAL statement, but I never used it and also I am not sure it exists
> in gambas2.
Yes it exists, however I'm not tough enough to tell if it can work that way
> But there are other ways, more efficient. One is to find object handlers
> using introspection. You can find all the children of a form and, based
> on their name, do things (you can also scan all the children and, when
> you find the one which has the right name, do the thing you want). The
I don't see (may be you're talking about iterating form content is a Variant)
> other one, which I would recommed, is to create dynamically you objects,
> especially if they are many, and keep a reference to them using arrays
> or collections. Or a mix of the two: you create a form visually in the
> IDE, then in a routine collect all the handlers, and from then on you
> always use those handlers. I suspect you are doing something very large...
No, in fact, not that big.
On 2nd thought, it wasn't a good idea (even if it has worked, code would have
been beeing too much obscur)
But I keep your idea about very large arrays because I'll soon need it :)
Regards
JY
--
A visit to a strange place will bring fresh work.
More information about the User
mailing list