No subject
Thu Oct 26 19:20:09 CEST 2017
The code looks as follows:
'
col1 AS NEW collection 'dummy property bag for the control
col2 AS NEW collection 'idem for second control
PUBLIC SUB _new()
' this part must be done for every control you want
' to have the extra properties.
col1.Add("control1","name")
col1.Add("Version1","version")
col1.Add("1","TabOrder")
col1.Add("","OldValue")
' and now the trick
TextBox1.tag=col1 'store it in the control
' here for the second control
col2.Add("control2","name")
col2.Add("Version2","version")
col2.Add("2","TabOrder")
col2.Add("","OldValue")
' and now the trick
TextBox2.tag=col2 'store it in the control
END
PRIVATE SUB DoSomethingWithIt()
'use the trick
'clear text
DIM property AS Variant
property = TextBox1.Tag
TextBox1.Text=Str(property ["name"])
' or the direct way
TextBox2.Text=Str(TextBox2.Tag["version"])
END
This way is also a nice method to use the .Tag for other workarounds.
Now you can use named items in the collection for all kind of things.
It's only a bit stupid to put it in the tag if it can be a global.
But with use of FOR EACH ctrl in ME.Controls the .Tag contains
the right collection of additional information for that control. i.e. the
OldValue if you press ESC (must set it with the gotfocus() for the control).
If Group is used then with the LAST.Tag this can also help.
FOR EACH ctrl in ME.Controls
if ctrl.tag["name"]="Image" THEN ctrl.Picture = Picture("ledon.xmp")
if ctrl.tag["name"]="btnClose" THEN ctrl.Enabled = True
ctrl.move(ctrl.tag["left"],ctrl.tag["top"])
NEXT
And for the missing .Index you have as object LAST when it belongs to a
control Group. In the event procedure you get in the LAST.Tag then all
the user properties for this control in the .Tag presented.
For VB it is IF ctrl.name = "myname" THEN ....
Gambas it is IF ctrl.tag["name"] = "myname" THEN ....
Why this dificult way you ask? I'll try to explain it as follows:
If you only use it for i.e. the .Name of the control it is easyer to cut
and past it to the .Tag and your ready.
But the Gambas controls are in basic QT widgets and they do not have all
and the same properties as the M$ VB controls.
Also while here the Gamabs interpreter is between your program in basic
and the QT controls it has to transform it in both directions and that is
not always posible or is difficult to implement for a easy working model.
For other problems the .Tag can deliver an solution as workaround too.
And it is that moment when you must use it for more then one thing.
This way gives it than an nice workaround and in the code you can use
simply the name for what you want to get from it.
Using a Collection, Object's or Array's should also posible,
is used here to be close to have the named property construction.
Is this something to add to the Wiki "DifferencesFromVB " Rob?
----------
Ron
More information about the User
mailing list