4/1/2019 0 Comments Delphi Serialize RecordSadly, the information needed to serialize a record is available only since Delphi 2010. If your application is developped on any older revision (e.g. Delphi 7, Delphi 2007 or Delphi 2009), you won't be able to automatically serialize records as plain JSON objects directly. On Tue, 15 Sep 2009 09:20:08 -0700, Joe Bren wrote: > for i:= 0 to High(FIntDblArray) do > begin > AStream.Write(FIntDblArray[i].anInt, Length(FIntDblArray) * SizeOf(TIntDblElement)); > AStream.Write(FIntDblArray[i].aDbl, Length(FIntDblArray) * SizeOf(TIntDblElement)); > end; > end; As before you can write th block in one go (The only time this isn't true is when your record contains reference types). You should be able to replace the whole block above: AStream.Write(FIntDblArray[0], Length(FIntDblArray) * SizeOf(TIntDblElement) ); and read everything in one go. -- Marc Rohloff [TeamB] marc -at- marc rohloff -dot- com. Joe Bren wrote: > I think I just answered my own question: > > > AStream.Read(FIntDblArray[i].anInt, Length(FIntDblArray) * > > SizeOf(TIntDblElement)); AStream.Read(FIntDblArray[i].aDbl, > > Length(FIntDblArray) * SizeOf(TIntDblElement)); > > The above should be > > AStream.Read(FIntDblArray, Length(FIntDblArray) * > SizeOf(TIntDblElement)); > > The same for the 'Write' as well. > > Am I wrong? Yes, slightly: AStream.Read(FIntDblArray[0], Length(FIntDblArray) * SizeOf(TIntDblEelement)); FintDblArray is only a pointer, and Stream.Read expects var parameters, so you would be writing over the pointer, and not into the array. -- Rudy Velthuis (TeamB) 'Louis Pasteur's theory of germs is ridiculous fiction.' -- Pierre Pachet, Professor of Physiology at Toulouse, 1872.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |