Menu Content/Inhalt
Start arrow HS Object Kernel arrow HS OK - Articles arrow Basics of the construction and functionality of HSOK
Basics of the construction and functionality of HSOK: THSBaseObject class Print
20 June 2007
Article Index
THSField class
THSBaseObject class
THSObject class
THSBaseList and descendants
"Weak" and "strong" references
Unicode support
XML support
The kernel object

THSBaseObject class

THSBaseObject 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:

  1. 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'),
  2. 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,
  3. 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,
  4. 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.