Clone wiki

TT's Persistent Objects for REALbasic / Home

About these classes

These free classes make it possible to easily store the properties of select classes in a database, without having to deal with RecordSets and all the other DB specifica such as SQL commands for creating tables or deleting rows.

Basically, they're used as follows:

  1. At program start, you specify a file location for the database once, along with providing a sample object of each class you want to store in the database.
  2. You define your classes with properties as usual. You make them a subclass of TTsPersistentObject and add a special attribute to all properties you want to have stored in the database.
  3. To store the properties of such an object, you simply call its TTsPersistentSave() function. That adds all the marked properties in the database, in a table named after the class. If you call TTsPersistentSave() again later on the same object, its properties will be updated in the database.
  4. To retrieve objects for a specific class from the database, you use a TTsPersistentIterator object that you get from the AllItemsOfClass() function. If you do not want all objects but only specific ones, you can use ItemsOfClassMatchingPredicate() or ItemsOfClassWithPropertyMatching().
  5. To remove objects from the database again, call their TTsPersistentRemove() function.
  6. You can even easily make relational references from one object to another, and these references will be stored in the database as well. See the example code, where it uses AlbumID or LibraryID.

There are more specialized features, including better control over the naming of columns and tables, but for the most common uses, that's all you need.


See the Example Project page.


  • Only the following property types may be used for this mechanism: All Integer sizes, Double and Single, String, and references to other persistent objects via the TTsPersistentObjectID class. Not supported are Arrays, Dictionary, MemoryBlock and other arbitrary classes. Those need to be turned into persistent classes that use the supported property types. An example of this is used in the sample project: Even though the Songs could be seen as an array belonging to an Album, they're made into their own class, and instead of having the Album reference the Songs, you go the other way by having each Song belowing to one Album via a reference.


Public domain, i.e. use it as if it's yours.