ReadExpression, WriteExpression, ReadMethod, WriteMethod
These are the methods that make builders and wizards possible. ReadExpression and WriteExpression give you access to properties containing expressions (as opposed to values). ReadMethod and WriteMethod let you access and change method code.
Usage |
cPropExpression = oObject.ReadExpression( cProperty ) lSuccess = oObject.WriteExpression( cProperty, cPropExpression ) cCode = oObject.ReadMethod( cMethod ) lSuccess = oObject.WriteMethod( cMethod, cCode [, lCreateIt ] ) |
Parameter |
Value |
Meaning |
cProperty |
Character |
The name of the property whose expression is being accessed or changed. |
cPropExpression |
Character |
An expression beginning with "=" that is assigned to cProperty. The expression is not evaluated in the WriteExpression call, but is stored to the property for evaluation at runtime. |
cMethod |
Character |
The name of the method whose code is being accessed or changed. |
cCode |
Character |
The code for cMethod. Lines are delimited with CHR(13). |
lCreateIt |
.T. |
cMethod should be created if it doesn't exist. |
.F. or omitted |
An error occurs if cMethod doesn't exist. |
|
lSuccess |
Logical |
Indicates whether the change was successful. |
In some versions, munging up the expression by skipping or mismatching a pair of string delimiters returns the informative "Unknown error code: " followed by a negative number. If you see this, try reworking your expression; something in there is confusing FoxPro. This bug was fixed in one of the service packs for VFP 6. |
Example |
* Set a form's caption to include today's date. * Get a reference with aSelObj(). = aSelObj(aSelect, 1) * Now assign the property: aSelect[1].WriteExpression("Caption", ; '= "My Form - " + MDY(DATE())') * Set the DynamicForeColor property of a grid column. * First we put a reference to the grid in aSelect[1]. * Make sure the grid is selected, then: = aSelObj(aSelect) * Now we can work with it. aSelect[1].Column1.WriteExpression("DynamicForeColor", ; '= "IIF(balance<0, RGB(255,0,0), RGB(0,0,0)"') * Hmm, maybe we want all columns to have that. Let's * set the grid's Init to do it for all columns, but we * don't want to lose anything already in the Init. cInitCode = aSelect[1].ReadMethod("Init") aSelect[1].WriteMethod("Init", cInitCode + CHR(13) + ; [This.SetAll("DynamicForeColor", ; "IIF(balance<0, RGB(255,0,0), RGB(0,0,0))")]) |
See Also |