Hi I have defined some records in my project which may be consisted of other records and also dynamic arrays of normal data types and other records , it is n example of a record type
Type1=record
x:integer;
end;
Type2=record
Y:array of X;
str:string;
end;
When I tried to save one of variables of these records type to file with blockwrite function like this :
var
Temp1:Type2;
begin
setlength(temp1.y,100);
blockwrite(MyFile,Temp1,sizeOf(Temp1);
it just wrote as much as the size of pure record is ,but temp1 has a dynmic arrays which is resized , Could someone please tell me how I can write a complex record to a file , I mean something like what is used in VB6 . Thanks
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With