Closed eugeneloza closed 6 years ago
Would require using AdvancedRecords
to work on records.
Or write those through Interface
. While it would not work for records, the implementation is still different for every data element.
The only thing that actually is the problem in Modular or This approach is Iterator
s, which would work differently for different data types. I need to create some convenient API to use those, otherwise each save/load operation would require enormous amount of creativity, each time with different approach. However, starting at least somewhere is a good start (e.g. iterating on TStringList
, etc.). Thou, I don't want to do it in the wrong way to be forced to rewrite too much in future.
Hmmm, can I pass a "Generic TObjectList
" as a procedure parameter to use such stuff as Count
to iterate on items? Should work, needs testing. Or is there any reliable way to iterate on "any" list type / array type?
Writing integers/records can be implemented by Type Helper
s as it's done for integer.ToString
in SysUtils
, etc.
Thinking aloud:
WriteInteger(const Doc: TXMLDocument; const Parent: TDOMElement; const Name: string; const Value: integer);
WriteString(const Doc: TXMLDocument; const Parent: TDOMElement; const Name: string; const Value: string);
WriteFloat(const Doc: TXMLDocument; const Parent: TDOMElement; const Name: string; const Value: DFloat);
...
WriteIntegerXYZ(const Doc: TXMLDocument; const Parent: TDOMElement; const Name: string; const x, y, z: integer);
WriteFloatXYZ...
...
type TReaderProcedure = procedure(const Parent: TDOMElement; const Name: string) of object;
ReadIterator(const Parent: TDOMElement; const Name: string; const Reader: TReaderProcedure);
I don't like passing , thou it doesn't look clean for me.Doc: TXMLDocument
, we can make it a global variable (as there will always be only one XML file open at the moment secured by TCriticalSection
)
We're using XMLdoc.CreateElement
and XMLdoc.CreateTextNode
at the moment. So passing a procedure pointer as a parameter is also a bad solution.
Practically I'd better be with this one:
SomeList := ReadSomeList(Parent; Name);
WriteSomeList(Document, Parent, Name, SomeList);
Almost there. Creating 2 data-type specific issues and closing this one.
Define
maybe in
DObject
, maybe inWObject
(not to mess with abstract classes where it's not needed).Still thinking about it. Should replace #55 and #351 - looks like a cleaner and nicer solution.