Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's my variation on this. What I did, having got fed up with the same repetitive code, was to name all the edit boxes according to the XML node names I wanted, then iterate around the components and output their values. The XML code should be obvious, and I only have an edit and checkbox, but you should be able to see the idea.</p> <pre><code>procedure TfrmFTPSetup.LoadFromXML(szFileName : string); var xComponent : TComponent; nLoop : Integer; xMainNode : TXmlNode; xDocument : TNativeXml; begin inherited; xDocument := TNativeXml.Create; try xDocument.LoadFromFile(szFileName); xMainNode := xml_ChildNodeByName(xDocument.Root, 'options'); for nLoop := 0 to ComponentCount - 1 do begin xComponent := Components[nLoop]; if xComponent is TRzCustomEdit then begin (xComponent as TRzCustomEdit).Text := xMainNode.AttributeByName[xComponent.Name]; end; if xComponent is TRzCheckBox then begin (xComponent as TRzCheckBox).Checked := xml_X2Boolean(xMainNode.AttributeByName[xComponent.Name], false); end; end; finally FreeAndNil(xDocument); end; end; procedure TfrmFTPSetup.SaveToXML(szFileName : string); var xComponent : TComponent; nLoop : Integer; xMainNode : TXmlNode; xDocument : TNativeXml; begin inherited; xDocument := TNativeXml.CreateName('ftpcontrol'); try xMainNode := xml_ChildNodeByNameCreate(xDocument.Root, 'options'); for nLoop := 0 to ComponentCount - 1 do begin xComponent := Components[nLoop]; if xComponent is TRzCustomEdit then begin xMainNode.AttributeByName[xComponent.Name] := (xComponent as TRzCustomEdit).Text; end; if xComponent is TRzCheckBox then begin xMainNode.AttributeByName[xComponent.Name] := xml_Boolean2X((xComponent as TRzCheckBox).Checked); end; end; xDocument.XmlFormat := xfReadable; xDocument.SaveToFile(szFileName); finally FreeAndNil(xDocument); end; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    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