I have a big record which is consist of many fields with different types and also dynamic arrays. I want to save it to a file and then read it back. Imagine this simple record:
TCustomRecord = Record
Field1 : array of integer;
Field2 : Integer;
Field3 : String;
end;
Normally I have to use something like this to save this record to a file:
var
f : File of TCustomRecord;
cr : TCustomeRecord;
begin
Write(f, cr);
end;
But it doesn't work because of dynamic array and string type.
So the question is:
Is there a way to save (export) it to a TXMLDocument
without going through all the fields? (I mean adding field-by-field using addChild()
)
Click File > Save As, and select the location where you want to save the file. , point to the arrow next to Save As, and then click Other Formats. In the File name box, type a name for the XML data file. In the Save as type list, click XML Data, and click Save.
To summarize: An XML file is a file used to store data in the form of hierarchical elements. Data stored in XML files can be read by computer programs with the help of custom tags, which indicate the type of element.
Retrieving information from XML files by using the Document Object Model, XmlReader class, XmlDocument class, and XmlNode class. Synchronizing DataSet data with XML via the XmlDataDocument class. Executing XML queries with XPath and the XPathNavigator class.
To save the XML document, on the File menu, click Save. To exit XML Notepad, on the File menu, click Exit.
Your XML library obviously needs to know what the fields' values are, or else it cannot serialize them, so you're going to have to go "through all the fields" at some point. Whether you do it manually or have some way of traversing your data structure automatically (like with RTTI) makes no difference. Something has to look at all the fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With