Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you should follow up on your idea of giving the TSomething class serialization methods of it's own.</p> <p>Here's an example, using XML for serialization:</p> <pre><code>TSomething = class(TPersistent) protected FNumber: Integer; FLine: String; public procedure WriteToXmlNode(XmlNode: IXmlNode); procedure ReadFromXmlNode(XmlNode: IXmlNode); published property Number: Integer read FNumber write FNumber; property Line: String read FLine write FLine; end; TOther = class(TPersistent) protected FSomething: TSomething; public procedure WriteToXmlNode(XmlNode: IXmlNode); procedure ReadFromXmlNode(XmlNode: IXmlNode); published property Something: TSomething read FSomething write FSomething; end; </code></pre> <p>In other words, letting each of the classes know how to serialize themselves to XML.</p> <p>The write method of TOther will then look like this:</p> <pre><code>procedure TOther.WriteToXmlNode(XmlNode: IXmlNode) var ChildNode: IXmlNode; begin // Write something ChildNode := XmlNode.AddChild('Something'); Something.WriteToXmlNode(ChildNode); end; </code></pre> <p>And the read method will look like this:</p> <pre><code>procedure TOther.ReadFromXmlNode(XmlNode: IXmlNode) var ChildNode: IXmlNode; begin // Read ChildNode := XmlNode.ChildNodes.First; while Assigned(ChildNode) do begin // Read something if ChildNode.NodeName = 'Something' then Something.ReadFromXmlNode(ChildNode); // Next child node ChildNode := ChildNode.NextSibling; end; end; </code></pre> <p>That's the general gist of it. </p> <p>I think you'll be using a similar approach in your example, even if you do not choose to serialize to XML.</p> <p><strong>Edit</strong>: It was a bit unclear what you wanted in your question. If you're writing components, and you want the properties of the components to be properly serialized when you work with them at design time, this is not the way to go. The method I describe is for serializing arbitrary objects during runtime.</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.
 

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