Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How filling a property with an objectreference at design
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00168392
Message ID:
00168496
Vues:
21
Hi Thomas,

I would suggest a more flexible approach. Consider doing this.

1. Add a property to your base label class called BoundField.

2. Just fill this field in with alias.field name for each label.

3. Add a method called GetFieldObject to your base label class that looks like this.
LOCAL lnI

IF NOT EMPTY(This.BoundField)
    FOR lnI = 1 TO This.Parent.ControlCount
        IF ;
           TYPE("This.Parent.Controls(lnI).ControlSource") = "C" AND ;
           UPPER(ALLTRIM(This.Parent.Controls(lnI).ControlSource)) == UPPER(ALLTRIM(This.BoundField))

           This.BoundObj = This.Parent.Controls(lnI)
           EXIT
         ENDIF
     NEXT
ENDIF
Why do I suggest this approach? 1st of all, if you change the name of a control, by switching from a textbox to a combobox for example, you don't need to do any extra work. Second, you can just call this method in the label methods that need to refer to the object so you don't have extra object references floating around. Third, this approach isn't dependent on the instantiation order. If you just use an object reference as you've outlined, you're going to have to be very careful when you place your labels and controls on your forms. If the label is instantiated before the control, you're going to get an error when the BoundObj property is evaluated because it doesn't exist yet.

Lastly, regardless of which approach you take, make you you do a This.BoundObj = .NULL. in the Destroy of your label class to clear the object reference.
Mike Feltman

F1 Technologies
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform