Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Form - Controls
Message
De
07/08/2002 05:13:30
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00686734
Message ID:
00686921
Vues:
38
>Hi,
>
>Is there a generic way I can loop through the form controls and check their control source property?
>
>For e.g I can loop through the fields in a table by doing the following
>
>For nctr = 1 to FCount()
> * can take any required action I want
>EndFor
>
>Similarly can I do this for form controls. I want to determine if the control source is "X" then change the back color of the control to "yellow". I need to do this when the form loads because the control can vary each time.
>
>Thank you.
>Neetu Kumar


Hi there :-)
Here is class that can do this.
In order to use it you hv to make it as visual class (custom or shape).

Once you do that you can simply drop it on your form and add desired code
in place holder method called 'do_the_thing'
which receives all controls as parameters while being executed by
recursive method 'go_all_over'.
define class looper as custom

procedure go_all_over
LPARAMETERS ParentContainer
LOCAL i,oControl,ParentContainer
FOR each oControl in ParentContainer.Controls
    DO case
        CASE oControl.baseclass=="Pageframe"
            FOR i = 1 to  oControl.Pagecount
                this.go_all_over(oControl.Pages(i))
            NEXT

        CASE oControl.baseclass=="Container"
            this.go_all_over(oControl)

        CASE oControl.baseclass=="Grid"
            FOR i = 1 to  oControl.columncount
                this.go_all_over(oControl.columns(i))
            NEXT
        OTHERWISE
            this.do_the_thing(oControl) 
    ENDCASE
NEXT
this.do_the_thing(ParentContainer)

procedure do_the_thing
lParameters oControl


enddefine
So in the looper object (on your form) you will hv
something like this in 'do_the_thing' method
*procedure do_the_thing
lParameters oControl
if oControl.controlsource='X'
   oControl.backColor=rgb....
endif
When you need to execute code you will call
thisform.LOOPER1.go_all_over(thisform)
And thing will get done :-)

It is also applicable for other container based controls
like;
thisform.LOOPER1.go_all_over(thisform.myContainer)

If you hv trouble implementing this I can send you
whole thing as ready class in VCX.

Hope this can help you.
*****************
Srdjan Djordjevic
Limassol, Cyprus

Free Reporting Framework for VFP9 ;
www.Report-Sculptor.Com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform