BeforeDBGetProp, AfterDBGetProp, BeforeDBSetProp, AfterDBSetProp
These database events fire when the DBGetProp() and DBSetProp() functions are used.
Usage |
PROCEDURE DBC_BeforeDBGetProp( cName, cType, cProperty ) PROCEDURE DBC_AfterDBGetProp( cName, cType, cProperty ) PROCEDURE DBC_BeforeDBSetProp( cName, cType, cProperty, ePropertyValue ) PROCEDURE DBC_AfterDBSetProp( cName, cType, cProperty, ePropertyValue ) |
Parameter |
Value |
Meaning |
cName |
Character |
The name of the object in the database. |
cType |
Character |
The object type: DATABASE, TABLE, VIEW, FIELD, or CONNECTION. |
cProperty |
Character |
The property being read or changed. |
ePropertyValue |
Character, Numeric, or Logical |
The new value for the property. |
IF UPPER(cType) = "FIELD" AND UPPER(cProperty) = "CAPTION" * Look up the caption for the specified field in a captions table. * oUser is a global user object and cLanguage is their selected language. lcCaption = GetFieldCaption(cName, oUser.cLanguage) RETURN lcCaption ELSE * Handle any other cases. ENDIFUnfortunately, this won't work, because database events can't return values back to the function that resulted in them being fired; they can only return .T. or .F. (in the case of Before events) to indicate that whatever fired them can continue.Instead, in BeforeDBGetProp, look up the desired value and use DBSETPROP() to change the property to that value, so that's what the function will return to the caller. In AfterDBGetProp, change the property back to its former value. Thanks to Ted for pointing out this cool solution.
A field name is passed without an alias to the cName parameter. |
Example |
* Prevent someone from turning off database events. PROCEDURE DBC_BeforeDBSetProp(cName, cType, cProperty, ; ePropertyValue) RETURN NOT (UPPER(cName) == UPPER(JUSTSTEM(dbc())) AND ; UPPER(cType) = "DATABASE" AND ; INLIST(UPPER(cProperty), "DBCEVENTS", "DBCEVENTFILE")) * Return your own custom string rather than the underlying * property. PROCEDURE DBC_BeforeDBGetProp(cName, cType, cProperty) IF UPPER(cName) = "COMPANY" AND ; UPPER(cType) = "FIELD" AND ; UPPER(cProperty) = "CAPTION" DBSETPROP("Customer.Company", "Field", "Caption", "Nom") ENDIF PROCEDURE DBC_AfterDBGetProp(cName, cType, cProperty) IF UPPER(cName) = "COMPANY" AND ; UPPER(cType) = "FIELD" AND ; UPPER(cProperty) = "CAPTION" DBSETPROP("Customer.Company", "Field", "Caption", "Name") ENDIF |
See Also |