title: Delphi - Saving Records to File using Streams
body: <p>Delphi Tokyo - I have a parameter file that I am needing to save (and later load) from disk.  The parameters are a series of record objects.  There is one HEADER record and then multiple COMMAND records.  These are true records (i.e type = records).  The HEADER record has String, Boolean, Integer, and TStringList types within it.  I save, which appears to work fine, but when I load, whatever is AFTER a TStringList causes a Stream read error.  For example...</p>
  
  <pre><code>type tEDP_PROJ = record
     Version : Integer;
     Name: String;
      ...
     ColList1: TStringList;
     ColList2: TStringList;
     ReadyToRun : Boolean;
     ...
   end;
  </code></pre>
  
  <p>When I read ReadyToRun I get a Stream read error.  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. It is interesting to note that ColList2 loads fine (even though it is NOT the first TStringList). </p>
  
  <p>I am specifying the Encoding method when I save the TStringList.</p>
  
  <pre><code>...
  ColList1.SaveToStream(SavingStream, TEncoding.Unicode);
  ColList2.SaveToStream(SavingStream, TEncoding.Unicode);
  </code></pre>
  
  <p>I am using the same encoding when I load from the (file) Stream.</p>
  
  <pre><code>...
     ColList1.LoadFromStream(SavingStream, TEncoding.Unicode);
     ColList2.LoadFromStream(SavingStream, TEncoding.Unicode);
  </code></pre>
  
  <p>Note that when I create the StringList, I am just doing the standard create...</p>
  
  <pre><code>ColList1 := TStringList.Create;
  </code></pre>
  
  <p>When I save and load, I am following the examples Remy gave <a href="https://stackoverflow.com/questions/37424546/delphi-write-read-variables-and-records-to-from-file">here</a>...</p>
  
  <p>The TStringList appears to be changing the way that the stream reads non-TStringList types...  What do I need to do to fix this?</p>