xHarbour Reference Documentation > Class Reference (textmode) |
Abstract base class for user-defined persistent object.
The HBPersistent() class is an abstract class for the creation of persistent objects. When user-defined classes should become persistent, they must inherit from HBPersistent() which provides methods for converting an object to/from a binary string and/or file on disk.
All instance variables declared with the PERSISTENT attribute are preserved and re-assigned when a persistent object is converted to a binary string and back to the Object data type.
Note: if code blocks are stored in instance variables of a persistent object, the same restrictions apply as outlined with function HB_Serialize().
See also: | CLASS, DATA, HB_Serialize() |
Category: | Object functions , xHarbour extensions |
Source: | rtl\persist.prg |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example demonstrates the steps required to make objects // persistent. Only the instance variables with the PERSISTENT // attribute are written to and restored from the file. #include "HbClass.ch" PROCEDURE Main LOCAL obj, cPersistent obj := test():new() obj:volatile := "Volatile" obj:show() obj:value := "Data from file" obj:saveToFile( "Persist.txt" ) obj := NIL WAIT "obj is gone, press a key..." obj := Test():new() obj:loadFromFile( "Persist.txt" ) obj:show() ? "Elapsed:", Seconds()-obj:secs RETURN CLASS Test FROM HBPersistent DATA value INIT "Test persistent Object" PERSISTENT DATA date INIT Date() PERSISTENT DATA time INIT Time() PERSISTENT DATA secs INIT Seconds() PERSISTENT DATA volatile METHOD show ENDCLASS METHOD Show ? ::value ? "Creation Date:", ::date ? "Creation Time:", ::time ? " Timestamp:", ::secs ? "Volatile data:", ::volatile RETURN
http://www.xHarbour.com