[Gambas-user] tags

Doriano Blengino doriano.blengino at ...1909...
Sat Nov 14 08:27:22 CET 2009


Jean-Yves F. Barbier ha scritto:
> Hi,
>
> Is it possible to recover any kind of widget's value only from
> its tag (as far as tags are all numerics 0,1,2...) from into a loop?
>
>   
I am not sure about what you want... anyway...

It seems to me that the TAG property is a variant, so you can assign any 
kind of value to it (at least in code); using the GUI designer seems to 
let you only use strings.

When you later access the TAG property, its value will retain the type 
of data you assigned to it. For example, I just tried this:

    PUBLIC SUB Form_Open()
      TextArea1.Tag = listview1
      TextBox1.Text = TextArea1.Tag.name
      TextBox1.Text = TextArea1.Tag
    END

The first line shows that you can assign an arbitrary object to the TAG 
field.
The second line shows that you can read what is stored in TAG; having 
you stored a ListView, then you can read its Name property, The text of 
TextBox1 now gets assigned to the string "Listview1".
The third line fires an error, but only at runtime; during compilation 
gambas can not know what the content of Textarea1.Tag is, so it can not 
decide if this content is compatible to a string (to be stored in 
TextBox1.text). At runtime, instead, gambas reads the content of 
TextArea1.tag and it finds it is an object: the object ListView1; now, 
it can not assign an object to a string, so it rises an errore (expected 
string, got ListView instead...).

About "recover any kind [...] from into a loop", I don't understand. 
Perhaps you want to scan all the controls residing on a form - there is 
the Controls[] property for that. Or you want to stream out all the 
properties of an object, perhaps to a file? This is possible too, I 
think - look at the Object class (or the Class class, can't remember), 
which has method to inspect... objects.

Regards,

-- 
Doriano Blengino

"Listen twice before you speak.
This is why we have two ears, but only one mouth."





More information about the User mailing list