|
Basics of the construction and functionality of HSOK: THSBaseObject class |
|
|
20 June 2007 |
|
Page 3 of 9 THSBaseObject classTHSBaseObject is an abstract class inheriting from THSField, defining properties and methods common for complex structures like objects, lists and collections. Methods and properties worth mentioning are: SaveToFile, LoadFromFile and LoadFromResConst – general methods for reading and writing objects (lists, collections) from a stream of a given type (binary, text, XML, RES, with compression and/or encryption). It does not always have to be files, e.g. after saving an object to a resource file by Object.SaveToFile('file.res',osfRES) it may be included in the code with directive {$R file.res} and then read by Object.LoadFromResConst('file'), HasValue – boolean array property. For given index returns TRUE when corresponding element of the structure is not NULL. Setting given index to FALSE clears data of the chosen element. For objects the elements are fields, for lists and collections - their items, Owner – a refernce to the owner of an object (list, collection). It allows iteration through the object tree in the "up" direction (from leaf to root) in runtime, GetHashCode – function returning a code calculated from object content. A very useful function to check e.g. whether an object has changed in the result of edition.
THSBaseObject class implements also a very useful mechanism of so called "strong" references, described later in this article. A "strong" reference is automatically cleared by HSOK (set to nil) when referenced object is released. Strong references are represented by THSStrongRefField class and can be fields in other objects. Fields of this type are supported by THSObject class.
|