Re: [Gambas-user] Problems with controls - text property
Brought to you by:
gambas
From: Steven L. <st...@re...> - 2007-04-27 11:45:25
|
OK Benoit, I changed it from control to object. It's right that it's a bit slower, but user wont notice, so all is ok now. Towards your explanation in english of Static typing and Virtual Classes : I think your english is perfect, but my japanese is awfull ;-) I might have to learn something about OO in the end :-( Steven Le vendredi 27 avril 2007 00:52, Benoit Minisini a =E9crit=A0: > On vendredi 27 avril 2007, ron wrote: > > On Thursday 26 April 2007 23:05, Steven Lobbezoo wrote: > > > Hi, > > > > > > I dont get it, if I do the following : > > > ---------------------------------------------------------------------= =2D- > > >-- ---- FOR EACH ctrl IN ME.Controls > > > IF ctrl.Name =3D tmp THEN > > > IF ctrl.Tag <> ctrl.Text THEN > > > ' ok, we've changed something, let's write it back > > > IF SqlPrt THEN SqlPrt =3D SqlPrt & "," > > > SqlPrt =3D SqlPrt & " " & Object.GetProperty(ctrl, "Name"= ) & > > > " =3D '" & Object.GetProperty(ctrl, "Text") & "' " > > > END IF > > > BREAK > > > END IF > > > NEXT > > > ---------------------------------------------------------------------= =2D- > > >-- ---- > > > > > > 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 =3D= 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 =3D SqlPrt & " " & Object.GetProperty(ctrl, "Name") & " =3D '" & > > Object.GetProperty(ctrl, "Text") & "' " can be > > SqlPrt =3D SqlPrt & " " & ctrl.Name & " =3D '" & 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 =3D new TextBox(Form) as "Tmp" > > > > and use in your Sub > > > > FOR EACH ctrl IN ME.Controls > > IF ctrl.ID =3D 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 =3D YourIdCollection['tmp'] THEN > > IF ctrl.Tag <> ctrl.Text THEN > > > > SqlPrt =3D SqlPrt & " " & YourIdCollection.key & " =3D '" & ctrl.Text= & "' > > " or > > SqlPrt =3D SqlPrt & " " & "tmp =3D '" & ctrl.Text & "' " > > > > > > > > Ron > > Hmm... It is absolutely not that :-) > > The Name property has been implemented for a while. > > The problem is that Steven didn't understand that if *he* knows that his > test is true only for control having the Text property, Gambas does not. > > Gambas uses static typing with virtual dispatching. > > 'Static typing' means that the class of an object is given by the > declaration of the variable that contains its reference. > > 'Virtual dispatching' means that the symbol (method or property) applied = to > this reference will call the implementation of the true object class, not > the class given by the declaration of the variable. > > So if the 'ctrl' variable is declared 'AS Control', then you can only use > symbols of the Control class on it. > > If you want Gambas to use dynamic typing, i.e. detects that the Text > property exists each time it uses it, then you must declare the 'ctrl' > variable 'AS Object'. But this is slower, as each symbol applied to 'ctrl' > will need a lookup in the symbol table of the object class. > > I hope I was clear, as it is difficult for me to explain that in English. > > Note that is exactly like C++, with classes having virtual methods only. > Except that C++ has no dynamic typing of course. > > Regards, |