Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can inheriting from TPersistent and then you can use the TJvAppXMLFileStorage (<a href="http://jvcl.delphi-jedi.org/" rel="nofollow noreferrer">JVCL</a>) component to serialize the TAlarm class.</p> <p><strong><em>Save a Object</em></strong></p> <pre><code>uses JvAppXMLStorage; Procedure SaveMyObject(MyAlarm : TAlarm) var MyStore: TJvAppXMLFileStorage; begin MyStore:= TJvAppXMLFileStorage.Create(nil); try MyStore.WritePersistent('', MyAlarm); MyStore.Xml.SaveToFile('C:\MyAlarm.xml'); finally MyStore.Free; end; end; </code></pre> <p><strong><em>Restore a Object</em></strong></p> <pre><code>uses JvAppXMLStorage; Procedure LoadMyObject(MyAlarm : TAlarm) var MyStore: TJvAppXMLFileStorage; begin MyStore:= TJvAppXMLFileStorage.Create(nil); try MyStore.FileName:='C:\MyAlarm.xml'; MyStore.Xml.LoadFromFile('C:\MyAlarm.xml'); MyStore.ReadPersistent('', MyAlarm); finally MyStore.Free; end; end; </code></pre> <h1>UPDATE</h1> <p>If you need to persist more than one object to the XML file you must assign a path (unique id) to the WritePersistent and ReadPersistent methods.</p> <p>See this example, </p> <p><strong><em>Multiple Persist</em></strong></p> <pre><code>Procedure SaveMyObjects(MyObjects : Array of TComponent); var MyStore: TJvAppXMLFileStorage; i : integer; begin MyStore:= TJvAppXMLFileStorage.Create(nil); try for i := Low(MyObjects) to High(MyObjects) do MyStore.WritePersistent(MyObjects[i].Name, MyObjects[i]); //In this case i use the name property of the component. MyStore.Xml.SaveToFile('C:\Tools\MyAlarm.xml'); finally MyStore.Free; end; end; </code></pre> <p>to save the components</p> <pre><code>SaveMyObjects([Button1,Button2,Edit1,Edit2]); </code></pre> <p><strong><em>Multiple LOAD</em></strong></p> <pre><code>Procedure LoadMyObjects(MyObjects:Array of TComponent); var MyStore : TJvAppXMLFileStorage; i : integer; begin MyStore:= TJvAppXMLFileStorage.Create(nil); try MyStore.FileName:='C:\Tools\MyAlarm.xml'; MyStore.Xml.LoadFromFile('C:\Tools\MyAlarm.xml'); for i := Low(MyObjects) to High(MyObjects) do MyStore.ReadPersistent(MyObjects[i].Name, MyObjects[i]); finally MyStore.Free; end; end; </code></pre> <p>To restore the properties</p> <pre><code>LoadMyObjects([Button1,Button2,Edit1,Edit2]); </code></pre> <p>Another option to load</p> <pre><code>Procedure LoadMyObjectById(Id:String;MyObject:TComponent); //using the id of the object var MyStore : TJvAppXMLFileStorage; i : integer; begin MyStore:= TJvAppXMLFileStorage.Create(nil); try MyStore.FileName:='C:\Tools\MyAlarm.xml'; MyStore.Xml.LoadFromFile('C:\Tools\MyAlarm.xml'); MyStore.ReadPersistent(id, MyObject); finally MyStore.Free; end; end; </code></pre> <p>you must run it this way</p> <pre><code>LoadMyObjectById(Button1.Name,Button1); //Again using the Name property. </code></pre> <p>I hope this example will be useful ;)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload