Saving a TObject to a File

前端 未结 7 1593
无人及你
无人及你 2021-02-04 12:45

How can one save an Object, in its current state, to a file? So that it can immediately be read and restored with all its variables.

7条回答
  •  萌比男神i
    2021-02-04 13:32

    1. Very simple and efficient solution: DragonSoft's XML Class Serializer
    2. Also you can use JVCL TJvAppXMLFileStorage:

      uses JvAppXMLStorage;

      var
        Storage: TJvAppXMLFileStorage;
      begin
        Storage := TJvAppXMLFileStorage.Create(nil);
        try
          Storage.WritePersistent('', MyObject);
          Storage.Xml.SaveToFile('S:\TestFiles\Test.xml');
          Storage.Xml.LoadFromFile('S:\TestFiles\Test.xml');
          Storage.ReadPersistent('', MyObject);
        finally
          Storage.Free;
        end;
      end;
      

提交回复
热议问题