[Gambas-user] Problems with controls - text property
ron
ronstk at ...239...
Fri Apr 27 00:24:36 CEST 2007
On Thursday 26 April 2007 23:05, Steven Lobbezoo wrote:
> Hi,
>
> I dont get it, if I do the following :
> -----------------------------------------------------------------------------
> FOR EACH ctrl IN ME.Controls
> IF ctrl.Name = tmp THEN
> IF ctrl.Tag <> ctrl.Text THEN
> ' ok, we've changed something, let's write it back
> IF SqlPrt THEN SqlPrt = SqlPrt & ","
> SqlPrt = SqlPrt & " " & Object.GetProperty(ctrl, "Name") & " = '"
> & Object.GetProperty(ctrl, "Text") & "' "
> END IF
> BREAK
> END IF
> NEXT
> -----------------------------------------------------------------------------
>
> I get "Unknown symbol 'test' in class control"
>
> Certanly there are controls in the form that not have a property 'text', but
> I filter them out with the line " IF ctrl.Name = tmp THEN "
> Since ALL the controls that satisfy this condition have a property "text".
>
> If I look into the vars ctrl.Tag and ctrl.Text there is a value, no problem
> there.
>
> So, why do I get this error ?
>
> Steven
>
Because the controls does not have a name property.
What you see "as" name is in the design mode.
This 'name' thing does have a long history of wishes but Benoit
decided not to implement and suggest to use the 'Tag' property for
storing your name of the control.
BTW
SqlPrt = SqlPrt & " " & Object.GetProperty(ctrl, "Name") & " = '" & Object.GetProperty(ctrl, "Text") & "' "
can be
SqlPrt = SqlPrt & " " & ctrl.Name & " = '" & ctrl.Text & "' "
if the .name was implemented.
The other way is using the useless ID property.
DIM YourTmp as Control
' you need next line to get the ID of created control in a fixed way
YourTmp = new TextBox(Form) as "Tmp"
and use in your Sub
FOR EACH ctrl IN ME.Controls
IF ctrl.ID = YourTmp.ID THEN
IF ctrl.Tag <> ctrl.Text THEN
You can also in design mode fill the 'Tag' with the name of the
control and in the Form.Open or .new read the 'Tag', store it in
collection and clear the content of 'Tag'
the collection key is the content of the 'Tag' and the value the .ID of the control
FOR EACH ctrl IN ME.Controls
IF ctrl.ID = YourIdCollection['tmp'] THEN
IF ctrl.Tag <> ctrl.Text THEN
SqlPrt = SqlPrt & " " & YourIdCollection.key & " = '" & ctrl.Text & "' "
or
SqlPrt = SqlPrt & " " & "tmp = '" & ctrl.Text & "' "
Ron
More information about the User
mailing list