Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2003-06

(Auto) XML Record Loader & RTTI Info

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

RRC2Soft
Show quoted text 11 lines
> >> I want to know if there's a tool that creates the OpenXML code > >> needed for loading and saving an entire record from/to XML > >> automatically. > > > >What would the purpose of this be ? > > Imagine that you have an structure in memory and you want to save > it from disk and to load it from disk, but in XML format. > (bla, bla, bla) If there was record RTTI, I think it could be done runtime?

Hmmm maybe. In that case a record can be processed like a tree structure...

TLayer = Record
            L1,L2:Integer;
TZone = Record
           ID:Integer;
           Tile:Array[1..3] of TLayer;
        End;

=>

proc CreateXML(Type,OptInfo)
begin
for every field in the record

    begin
       if Type = Simple-Type
          Store in XML File
       if Type = Array-Type
          For i=StartArray to EndArray
              CreateXML(Array-Type,i)
       if Type = Record-Type
          CreateXML(record-Type)
    end

end

=>

<TZONE>
<ID> Value </ID>
<TILE>
<TLAYER Pos='1'>
<L1> Value </L1>
<L2> Value </L2>
</TLAYER>
<TLAYER Pos='2'>
<L1> Value </L1>
<L2> Value </L2>
</TLAYER>
<TLAYER Pos='3'>
<L1> Value </L1>
<L2> Value </L2>
</TLAYER>
</TILE>
</TZONE>

...sort of.

How is RTTI information accesible from FreePascal/Delphi?

Rodrigo "Rui" R. (1/2 RRC2Soft)

Unknown author
to RRC2Soft
RRC2Soft wrote 61 lines
> > >> I want to know if there's a tool that creates the OpenXML code > > >> needed for loading and saving an entire record from/to XML > > >> automatically. > > > > > >What would the purpose of this be ? > > > > Imagine that you have an structure in memory and you want to save > > it from disk and to load it from disk, but in XML format. > > (bla, bla, bla) > > If there was record RTTI, I think it could be done runtime? Hmmm maybe. In that case a record can be processed like a tree structure... TLayer = Record L1,L2:Integer; TZone = Record ID:Integer; Tile:Array[1..3] of TLayer; End; => proc CreateXML(Type,OptInfo) begin for every field in the record begin if Type = Simple-Type Store in XML File if Type = Array-Type For i=StartArray to EndArray CreateXML(Array-Type,i) if Type = Record-Type CreateXML(record-Type) end end => <TZONE> <ID> Value </ID> <TILE> <TLAYER Pos='1'> <L1> Value </L1> <L2> Value </L2> </TLAYER> <TLAYER Pos='2'> <L1> Value </L1> <L2> Value </L2> </TLAYER> <TLAYER Pos='3'> <L1> Value </L1> <L2> Value </L2> </TLAYER> </TILE> </TZONE> ...sort of. How is RTTI information accesible from FreePascal/Delphi?

See the typinfo unit. It's used for instance in the classes.pas unit.

Michael.

RRC2Soft
See the typinfo unit. It's used for instance in the classes.pas unit. Michael.

OK, thx for the info ^_-

Rodrigo "Rui" R. (1/2 RRC2Soft)