Writing complex records to file
You can use https://github.com/KrystianBigaj/kblib (works with any dynamic records, also records that contains other records, etc.). Tested on Delphi 2006/2009/XE (it doesn't use extended RTTI introduced in D2010). No need to write save/load code manually (just one line to save/load any dynamic type - strings, records, dynamic arrays).
In your example it would be sth. like this:
TKBDynamic.WriteTo(lStream, lType2, TypeInfo(Type2));
To load it back:
TKBDynamic.ReadFrom(lStream, lType2, TypeInfo(Type2));
If anyone is interested how to deal with 'record versions', just post new issue and then I'll write some examples.
Similar questsion:
- How Can I Save a Dynamic Array to a FileStream in Delphi?
- Delphi 2010: How to save a whole record to a file?