DGL
https://delphigl.com/forum/

object to xml howto?
https://delphigl.com/forum/viewtopic.php?f=19&t=5981
Seite 1 von 1

Autor:  noeska [ Di Sep 26, 2006 21:30 ]
Betreff des Beitrags:  object to xml howto?

How do i convert an object to xml data?
I think of using a TRemotable descendant, but i do not understand on how to use the ObjectToSoap function. I think i should use it together with TXmlDocument, but how? Or am i going the hard way? I do not want to use third party components as i want to use turbo delphi.

Also i could use some info serializing objects in delphi e.g. how do i write my own serializing function? E.g. serialize to xml or even fancier to an sql query.... but first i need to learn the basics.... any tutorials on this topic?

Thanks in advance.

Autor:  luketheduke [ Mi Sep 27, 2006 16:09 ]
Betreff des Beitrags: 

The RTTI is able to serialize components, unfortunately not to XML. But to binary dfm and text dfm. And text dfm is a usable format, I'd think.

You only need to derive your classes from TComponent and pack everything you want to have saved into published properties.

You can then do it like this:

Code:
  1.  
  2. procedure Save(var data: TStream);
  3. begin
  4. if not assigned(data) then data := TMemoryStream.Create;
  5.  
  6. data.WriteComponent(someMyComponent);
  7. end;
  8.  
  9. function Load(data: TStream): TMyComponent;
  10. begin
  11.   Result := TMyComponent.Create(whereever_or_nil);
  12.   data.ReadComponent(Result);
  13. end;
  14.  


This works in principle, but I myself am currently fighting with it and just can't get it to work. However, I have a rather complicated structure.

Autor:  noeska [ Mi Sep 27, 2006 18:55 ]
Betreff des Beitrags: 

Using google again i found: http://www.delphipages.com/threads/thre ... 4&G=116542 this seems to do what i want, all i have to learn it is object inside object and list and arrays.

Autor:  luketheduke [ Fr Sep 29, 2006 14:58 ]
Betreff des Beitrags: 

*whistle*

Looks like something great! Seems like you helped me more than I did you ;)

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/