![delphi xe10 record delphi xe10 record](https://www.embarcadero.com/images/old/rad10/radstudioseattleheroshot720.png)
WriteLn(' Press Enter to free the list') Writeln('Value: ', MyRecList.Value, ' AByte: ', MyRecList.AByte) Property Items: PMyRec read Get default įunction TMyRecList.Add(Value: PMyRec): Integer įunction TMyRecList.Get(Index: Integer): PMyRec Here's a quick sample console app to demonstrate: program Project1 Values.The easiest way is to create your own descendant of TList. Values.LoadFromStream(MS, TEncoding.UTF8) Īnother option is to write the number of string elements in the TStrings object to your output stream, and then write the individual strings: procedure WriteStringsToStream(Stream: TStream Values: TStrings) Procedure ReadStringsFromStream(Stream: TStream Values: TStrings) Procedure WriteStringsToStream(Stream: TStream Values: TStrings) Stream.ReadBuffer(Result, Sizeof(Result)) Stream.WriteBuffer(Value, Sizeof(Value)) įunction ReadInt64FromStream(Stream: TStream): Int64 When loading back later, first read the Size, then read the specified number of bytes into an intermediate TMemoryStream, and then load that stream into your receiving TStrings object: procedure WriteInt64ToStream(Stream: TStream Value: Int64)
![delphi xe10 record delphi xe10 record](https://img2018.cnblogs.com/blog/78155/201811/78155-20181130162122654-1105066284.png)
One option is to save a TStrings object to an intermediate TMemoryStream first, then write that stream's Size to your output stream followed by the TMemoryStream's data.
![delphi xe10 record delphi xe10 record](https://www.trichview.com/shots/rvmedia/conference.png)
DELPHI XE10 RECORD CODE
Just like the earlier code needed to serialize String data and other variable-length data into a flat format to know where one field ends and the next begins, you need to serialize TStrings data as well. That is why you are getting streaming errors when trying to read/write any non- TStrings data after any TStrings data. When loading in a stream, TStrings.LoadFromStream() simply reads the ENTIRE stream (well, everything between the current Position and the End-Of-Stream, anyway). However, TStrings does not save any kind of terminating delimiter or size information to an output stream. What you are attempting to do will simply not work the way you are trying to do it, because TStrings data is variable-length and needs to be handled accordingly. In any case, this is not an encoding issue. Why are you using TEncoding.Unicode? TEncoding.UTF8 would have made more sense. The TStringList appears to be changing the way that the stream reads non-TStringList types. When I save and load, I am following the examples Remy gave here. Note that when I create the StringList, I am just doing the standard create. I am using the same encoding when I load from the (file) Stream.ĬolList1.LoadFromStream(SavingStream, TEncoding.Unicode) ĬolList2.LoadFromStream(SavingStream, TEncoding.Unicode) I am specifying the Encoding method when I save the TStringList.ĬolList1.SaveToStream(SavingStream, TEncoding.Unicode) ĬolList2.SaveToStream(SavingStream, TEncoding.Unicode) It is interesting to note that ColList2 loads fine (even though it is NOT the first TStringList). If I move it BEFORE TStringList (on both SAVE and LOAD routines) then ReadyToRun will load properly, but whatever is after the TStringList will cause an error. When I read ReadyToRun I get a Stream read error. I save, which appears to work fine, but when I load, whatever is AFTER a TStringList causes a Stream read error. The HEADER record has String, Boolean, Integer, and TStringList types within it. These are true records (i.e type = records). There is one HEADER record and then multiple COMMAND records.
DELPHI XE10 RECORD SERIES
The parameters are a series of record objects. Delphi Tokyo - I have a parameter file that I am needing to save (and later load) from disk.