title: Reading/writing dynamic arrays of objects to a file - Delphi
body: <p>Im trying to write some code which will read/write a dynamic array of objects to a file. The objects represent the structure of the java source code. I need to be able to scan the whole source code and gather information on Fields, Methods and Classes. I have an algorithm which does this and the result is kept in a structure of TFieldStruc, TMethodStruc and TClassStruc, all descendants of the TCoreStruc (a descendant of TObject). The java source code takes a couple of minutes to be scanned and have the virtual structure generated. Because of this my application scans all the source code once and saves it into a much more accessible format which is loaded when ever the IDE launches.</p>
  
  <p>Is there a way (other than exporting the objects 'to string' and then re-creating them again when they are loaded) to stream the entire three arrays of TFieldStruc, TMethodStruc and TClassStruc, to a file so they can be read later?</p>
  
  <p>I have tried reading and writing to a 'File of TFieldStruc..' and the TFileStream to save the objects to a file and read them back, but in both cases I get 'inaccessible value' in the debugger followed by an 'Access Violation' error as soon as the object is accessed again. If anyone has ideas on how to solve this problem it would be appreciated. Below is the code to TCodeStruc if any of its fields/methods may be causing issues:</p>
  
  <pre><code>type
    TCoreStruc = class(TObject)
      public
        LowerPointer : integer;
        HigherPointer : integer;
        Line : integer;
        Word : integer;
        Char : integer;
        CoreType : ansistring;
        IsPublic : boolean;
        IsPrivate : boolean;
        IsStatic : boolean;
        IsFinal : boolean;
        Name : ansistring;
        NestedStruc : TCoreStruc;
        constructor Create(Name, CoreType : ansistring; NestedStruc : TCoreStruc; IsPublic, IsPrivate, IsStatic, IsFinal : boolean);
        procedure UpdateValues(NestedStruc : TCoreStruc; IsPublic, IsPrivate, IsStatic, IsFinal : boolean);
        procedure SetPosition(Line, Word, Char : integer);
    end;
  </code></pre>