You need the so-called "serialization" mechanism.
1. Standard way
1.1 SaveToStream
In Delphi, we usually implement the SaveToStream method, which will save the contents of each object in the target TStream (either TFileStream or TMemoryStream ).
You will have to write serialization manually.
1.2 streaming in DFM format
See TWriter / TReader classes.
If you define your data in published properties, you can serialize them using these standard Delphi classes.
For some methods that can serialize any TCollection to and from JSON content, see this blog post .
2. RTTI
See for example this SO question .
In particular, the new extended RTTI (available since Delphi 2010) opens up new possibilities for serialization.
3. Use records instead of classes
If each element does not store a lot of content (some integer / logical), it makes sense to use records instead of objects. For speed and memory / fragmentation, it can be worth it.
Here is some shell capable of serializing any dynamic array , even containing nested records or dynamic arrays.
4. Use the database engine
Perhaps the best approach is not to get your data stuck in non-expandable binary form, which is the property of your application. If you want to add a property, you will have to manage it manually. Or, if you want to access your data from other applications, this can be difficult.
There are many database solutions - instead of using an external database (for example, MS SQL, FireBird or Oracle), it would be nice to embed the database in your application (much easier to install). It is worth mentioning SQLite , in which there are many wrappers , including our version (which will allow you to switch to any other database if you want to use MS SQL or Oracle).
You have other solutions - see this SO question - and if you need performance, take a look at our Big Table Library .