>I have a form class that is used by several forms. There are multiple databounded fields in each form. I would like to set the fields as readonly or not with one single generic method.
>What would be the best approach?
If thisform.SetAll() (and then digging into containers that have their own SetAll) and you haven't made provision for the controls used on your form to reference a common form property as necessary to detrmine if they're read-only or not (this is what I do), you need code that will build a list of the contained objects in the form during the Form's Init (this will work only if you don't programmatically add controls later) using AMEMBERS(). You'll need to spin down through this recursively (containers can contain controls, which may be containers...) something like:
PROCEDURE MakeAllObjReadOnly
LPARAMETER oObjToCheck
LOCAL aObjsInThis, nNumObj, i
nNumObj = AMEMBERS(aObjsInThis,oObjToCheck,2)
FOR i = 1 TO nNumObj
=MakeAllObjReadOnly(aObjsInThis[i])
ENDFOR
IF TYPE('oObjToCheck.ReadOnly') = 'L'
oObjToCheck.ReadOnly = .T.
ENDIF
RETURN
Then in your form's Init:
=MakeAllObjReadOnly(thisform)
This is not tested code; there's no error handling or checking to make sure that the ReadOnly property can be set at runtime in the code above. it should give you a simple starting place to write your own code for your forms.
Note that this function
is recursive, and it can create problems of its own with very deep containership.