Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Elegant solution anyone?
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00424090
Message ID:
00424459
Vues:
14
Hi Barton,

Couple of ideas:

1. What about giving all of your controls an oSecurity property, and then in the form init:
*-- MyBaseForm.Init(toSecurity)
this.lInit = .T.
this.oSecurity = toSecurity
this.SetAll("oSecurity",toSecurity)

*-- MyBaseForm.Refresh
IF this.lInit 
   *-- If form is initing, do the default
   *-- behavior (calling the refresh of all
   *-- objects on the form
   DoDefault() 
  
   *-- Prevent default behavior from repeating 
   *-- at the end of the method
   NODEFAULT

   *-- Set the flag to .F. to prevent
   *-- control Refresh calls from
   *-- syncing with security object
   this.lInit = .F.
ENDIF
Then in the refresh of the baseclass of your controls:
*-- MySpecialTextbox.Refresh
IF thisform.lInit
   this.GetValueFromSecurityObject()  && references this.oSecurity   
ENDIF
The only downside to this approach is that non-visible pages of pageframes do not refresh their controls. So you might need to put the following into the refresh() method of your base pageframe class:
*-- MySpecialPageFrame.Refresh
IF thisform.lInit
   FOR EACH loPage IN this.Pages
       loPage.Refresh()
   ENDFOR
   NODEFAULT
ENDIF
2. I know you already considered a form array, but here is code that has the individual controls register themselves with the form, and it is pretty simple to implement. Create an array on the form object, and then in the inits of the controls call a method of the form that registers itself with the form. The form will need a property called nControlCount and an array property called aControls[1].
*-- MySpecialTextbox.Init
thisform.Register(this)

*-- MyBaseForm.Register(toControl)
LPARAMETERS toControl
this.nControlCount = this.nControlCount+1
DIMENSION this.aControls[this.nControlCount]
this.aControls[this.nControlCount] = toControl

*-- MyBaseForm.Init(toSecurity)
this.oSecurity = toSecurity
*-- loop through registered controls
FOR EACH loControl IN this.aControls
    loControl.Synchronize(toSecurity)
ENDFOR
A benefit of this registration technique would be that not all controls would need to register themselves, just the ones that need to deal with the security object. The controls could even have a property (lRegisterMe) that defaults to .F.:
*-- MySpecialTextbox.Init
IF this.lRegisterMe
  thisform.Register(this)
ENDIF
Then you just need to set this property to .T. for the ones that need registering.

2. Create an object that knows how to loop through and drill down into the form. Then in the form init ask the object for each control it finds, and call a method. This would use the Iterator design pattern. The downside to this is that this iteration can be slow, and has to be done twice: once upon init and once upon destroy

Rick


>I'm sure many have floundered with this problem, and I hope someone has something better than the kludges I've been contemplating. I'm passing an object reference to a form. Many controls on the form are dependent on this object reference, which will be moved to a form property in Form.Init. I want the controls to establish their own link to the passed object, so what they need in effect is a "second init" after the Form.Init fires. I have a dozen different ways of making this work, but I don't especially like any of them; e.g. using global instead of passed object, creating form-level array of controls to call back when Form.Init fires, control refresh that only fires once... Any ideas?
Rick Hodder
MCP Visual Foxpro
C#, VB.NET Developer
Independent Consultant
www.RickHodder.com
MyBlog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform