-
1
- #1
Chris Miller
Programmer
In thread184-1826223 (which by the way earns more credit to Gerrit Broekhuis) I indicated that the SetAll method could be used to implement a GetAll(), too.
Here's the principle by which that would work:
Using the SetAll() method you can only set all properties of a specific name and - if you want - of a specific class to a value. But combine that with an assign method of a property and you can use a little trcikery to have a GetAll() method.
First of all, the idea stems from the fact that Thisform.SetAll() is a way to reach all controls of a form. At firt glimpse you only reach one property of them all. But then let that property have an assign method and you indirectly call that assign method, which can do other things than assigning the passed in value to the property.
Here's a simple example of how that would work to implement a GetAll():
Notice how thisform.Controls only returns the controls directly on the form, whereas Setall with the help of the assign method also gets the text2 textbox within container1.
And since GetAll is cascading into all objects on the form or within containers, pageframe etc. you get them all with one SetAll() call.
The only downside is, this needs the getall_assign method defined in all controls. Which you can see from my sample. I can't write a parent class of which both a container and a textbox (and a listbox, editbox, grid, etc) can inherit. So each base control needs this method implemented once. If you think such a parent would be possible by using the Control baseclass: In short no, that's just not possible.
If you'd impleent that in all base controls, it should be worth hte effort and be capable of more than just the getall functionality, you could pass in something that includes instructions (code) to process, so you could make the assign method mechanism a VFP message queue like the Windows messaging system and let the assign method react to different passed in parameters. Using a collection to gather the full list of controls then is just one example of what can be done with this mechanism.
Chriss
Here's the principle by which that would work:
Using the SetAll() method you can only set all properties of a specific name and - if you want - of a specific class to a value. But combine that with an assign method of a property and you can use a little trcikery to have a GetAll() method.
First of all, the idea stems from the fact that Thisform.SetAll() is a way to reach all controls of a form. At firt glimpse you only reach one property of them all. But then let that property have an assign method and you indirectly call that assign method, which can do other things than assigning the passed in value to the property.
Here's a simple example of how that would work to implement a GetAll():
Code:
o = CreateObject("form1")
Define Class form1 as form
ADD OBJECT text1 AS getalltextbox
ADD OBJECT container1 AS getallcontainer
Procedure Init()
Activate Screen
Clear
? 'all controls of form.Controls:'
For Each loControl in thisform.Controls
? loControl.name
EndFor
Local loAllControls as Collection
loAllControls = CreateObject("Collection")
Thisform.Setall("getall",loAllControls)
?
? 'all controls by GetAll'
For each loControl in loAllControls
? loControl.name
EndFor
EndProc
EndDefine
Define Class getalltextbox as TextBox
getall = .null.
Procedure getall_assign()
Lparameters toCollection
If Vartype(toCollection)='O'
toCollection.Add(This)
Endif
Endproc
EndDefine
Define Class getallcontainer as Container
getall = .null.
Add Object text2 as getalltextbox
Procedure getall_assign()
Lparameters toCollection
If Vartype(toCollection)='O'
toCollection.Add(This)
Endif
Endproc
EndDefine
Notice how thisform.Controls only returns the controls directly on the form, whereas Setall with the help of the assign method also gets the text2 textbox within container1.
And since GetAll is cascading into all objects on the form or within containers, pageframe etc. you get them all with one SetAll() call.
The only downside is, this needs the getall_assign method defined in all controls. Which you can see from my sample. I can't write a parent class of which both a container and a textbox (and a listbox, editbox, grid, etc) can inherit. So each base control needs this method implemented once. If you think such a parent would be possible by using the Control baseclass: In short no, that's just not possible.
If you'd impleent that in all base controls, it should be worth hte effort and be capable of more than just the getall functionality, you could pass in something that includes instructions (code) to process, so you could make the assign method mechanism a VFP message queue like the Windows messaging system and let the assign method react to different passed in parameters. Using a collection to gather the full list of controls then is just one example of what can be done with this mechanism.
Chriss