[Gambas-user] Parsing through all controls of a form

johnf jfabiani at ...1109...
Thu Jan 19 17:17:59 CET 2006


On Thursday 19 January 2006 06:04, Benoit Minisini wrote:
> On Wednesday 18 January 2006 23:41, johnf wrote:
> > On Wednesday 18 January 2006 14:36, Michael Wuest wrote:
> > > Hi there,
> > >
> > > in VB6 you can access all the controls of a form
> > > by doing
> > >
> > > for i0=0 to form1.controls.count - 1
> > >   print form1.controls(i0).name
> > > next i0
> > >
> > > how can I do similar things in Gambas? I played
> > > around with form1.children and for..each but I get
> > > an error every time after the fourth or fifth
> > > control saying that he is referencing himself...
> > >
> > > What is the correct method.
> > >
> > > Thanks,
> > > bye,
> > > Michael.
> >
> > Below is an example of how I looping thru all the controls on my form. 
> > It should provide an idea of how to do it. BTW I got this from the list.
> > Sorry I can't recall who provided the info (I thank person).
> >
> > John
> >
> > PUBLIC SUB ClearFields(formname AS Window)
> > 'a way to loop thru the controls
> >    DIM hControl, tabControl AS Control
> >    DIM iNumTabs, imynum AS Integer
> >    DIM i AS Integer
> >    DIM sNames AS String
> >    DIM myVariant AS Variant
> >
> >    FOR EACH hControl IN formname.Children
> >       IF Object.Class(hControl) = "TextBox" OR Object.Class(hControl) =
> > "ComboBox" OR Object.Class(hControl) = "TextArea" THEN
> >          SELECT CASE Object.Class(hControl)
> >
> >           CASE "TextBox"
> >             'myVariant = Object.GetProperty(hControl, "Text")
> >             Object.SetProperty(hControl, "Text", "")
> >           CASE "GridView"
> >              Object.Call(tabControl, "Clear")
> >          CASE "ComboBox"
> >
> >          CASE "TextArea"
> >              Object.Call(hcontrol, "Clear")
> >
> >          END SELECT
> >       ENDIF
> >
> >       IF Object.Class(hControl) = "TabStrip" THEN
> >          iNumTabs = Object.GetProperty(hControl, "Count")
> >          FOR i = 0 TO iNumTabs - 1
> >             Object.SetProperty(hControl, "Index", i)
> >              FOR EACH tabControl IN hControl[i].Children
> >               SELECT CASE Object.Class(tabControl)
> >                  CASE "TextBox"
> >                    Object.SetProperty(tabControl, "Text", "")
> >                CASE "GridView"
> >                    Object.Call(tabControl, "Clear")
> >                 CASE "TextArea"
> >                    Object.Call(tabControl, "Clear")
> >               END SELECT
> >             NEXT
> >          NEXT
> >          Object.SetProperty(hControl, "Index", 0)
> >       ENDIF
> >    NEXT
> >    'editmode(FALSE)
> >    'custno.Enabled = TRUE
> > END
>
> I just finished to implement the pseudo-collection "Window.Controls", that
> will allow you to recursively enumerate all controls on a form.
>
> Your loop will look like:
>
> FOR EACH hControl IN formname.Controls
>   ...
> NEXT
>
> You will get it in the next development version release.
>
> Regards,

Could you add an extra - tag property. We would have two (2) tag like 
properties.  So not to break older coding maybe you could add the new 
property with a different name - like tag2.
John   




More information about the User mailing list