Class DataObject() Foundation
Class function of the DataObject class.
The DataObject class provides objects with dynamic member and dynamic method support. DataObjects are designed to serve as a universal and lightweight transport mechanism between the different tiers of an application.
Using DataObjects is like using objects of any other class. However, unlike ordinary objects whose state and behavior remains static as declared in the class, members and methods can be added dynamically to a data object after the instance object is created. This is done by by sending :new() to a DataObject class object.
// Basic usage patterns of data objects.
//
PROCEDURE MAIN
LOCAL oDO
oDO := DataObject():New()
/* Explicit check for a member using IsMemberVar(),
* and access of a non-existing member
*/
? IsMemberVar(oDO, "lastname" ) // N
? oDO:LastName // NIL
/* Add a member implicitly by value assignment,
* the check for a member and output its value
*/
oDO:LastName := "Picard"
? IsMemberVar(oDO, "lastname" ) // Y
? oDO:LastName // "Picard"
/* Use DataObject as dictionary
*/
oDO:setNoIVar( "accept-language", "en-us" )
? oDO:getNoIVar( "accept-language" ) // "en-us"
/* Define a method via code block, execute
* the method
*/
oDO:DefineMethod( "print" , {|oSelf|QOut("Hello "+oSelf:LastName)} )
oDO:print() // "Hello Picard"
/* Add another member, redefine an existing
* method. Now implement the method using a
* function. Execute the method.
*/
oDO:FirstName := "Jean-Luc"
oDO:DefineMethod( "print", "displayname" )
oDO:print( "," ) // Jean-Luc, Picard
RETURN
/* A regular Xbase++ function. If used to implement a
* dynamic method of a DataObject, the first parameter
* passed to the function always is the DataObject
* itself.
*/
FUNCTION DisplayName(oSelf, cSeparator )
? oSelf:FirstName+cSeparator+" "+oSelf:LastName
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.