<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>serialize object Archives - Dragonsoft Technology View</title>
	<atom:link href="https://blog.dragonsoft.us/tag/serialize-object/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.dragonsoft.us/tag/serialize-object/</link>
	<description>Talk about Technologies, Software Architecture and Management</description>
	<lastBuildDate>Sun, 01 Mar 2009 23:00:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://blog.dragonsoft.us/wp-content/uploads/2022/04/logo-main-bw-150x150.png</url>
	<title>serialize object Archives - Dragonsoft Technology View</title>
	<link>https://blog.dragonsoft.us/tag/serialize-object/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">2577970</site>	<item>
		<title>How to serialize Delphi object</title>
		<link>https://blog.dragonsoft.us/2008/04/21/how-to-serialize-delphi-object/</link>
					<comments>https://blog.dragonsoft.us/2008/04/21/how-to-serialize-delphi-object/#comments</comments>
		
		<dc:creator><![CDATA[Serguei Dosyukov]]></dc:creator>
		<pubDate>Mon, 21 Apr 2008 15:51:20 +0000</pubDate>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[delphi]]></category>
		<category><![CDATA[Serialization in Delphi]]></category>
		<category><![CDATA[serialize object]]></category>
		<category><![CDATA[VCL]]></category>
		<category><![CDATA[VCL to XML]]></category>
		<category><![CDATA[VCL2XML]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml serialization]]></category>
		<category><![CDATA[xml to vcl]]></category>
		<category><![CDATA[XML2VCL]]></category>
		<guid isPermaLink="false">http://blog.dragonsoft.us/?p=170</guid>

					<description><![CDATA[<p>It has been a very lean and easy option of .Net to able serialize/deserialize any serializable object instance. Only closest option in Delphi is to stream the component using WriteComponent/WriteComponentRes of TStream/TWriter (used for Form storage as DFM, for example). It can be then read back using appropriate counterpart ReadComponent/ReadComponentRes. Depend on<a class="moretag" href="https://blog.dragonsoft.us/2008/04/21/how-to-serialize-delphi-object/"> Read more</a></p>
<p>The post <a href="https://blog.dragonsoft.us/2008/04/21/how-to-serialize-delphi-object/">How to serialize Delphi object</a> appeared first on <a href="https://blog.dragonsoft.us">Dragonsoft Technology View</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>It has been a very lean and easy option of .Net to able serialize/deserialize any serializable object instance.</p>
<p>Only closest option in Delphi is to stream the component using WriteComponent/WriteComponentRes of TStream/TWriter (used for Form storage as DFM, for example). It can be then read back using appropriate counterpart ReadComponent/ReadComponentRes.</p>
<p>Depend on your situation, simply calling .Assign method would work if you are coping data from one instance to another. But it only works between inherited classed which know about each other.</p>
<p>Can we find there something which will allow to pass objects states in more readable format?</p>
<p>There is a very powerful infrastructure available to do full serialization without knowing underlying class structure &#8211; <a href="http://en.wikipedia.org/wiki/RTTI" target="_blank">RTTI</a> (Run-time Type Information).</p>
<p>All functions we would be looking at are defined in TypInfo.pas unit.</p>
<p>First thing first. To be able to work within RTTI, you need to operate on the object which has <strong>published</strong> <strong>and public </strong>properties.</p>
<pre class="brush: delphi; title: ; notranslate">function GetPropList(TypeInfo: PTypeInfo;  out APropList: PPropList): integer;</pre>
<p>A function will return number and reference to the list (array) of properties published (public and published) by the class (<a href="http://en.wikipedia.org/wiki/VMT" target="_blank">VMT</a> information). List will also include published methods. Simply walking through it will give you an access to property/method information.</p>
<p>In our example we are not interested in the published methods, so lets filter it out:</p>
<pre class="brush: delphi; title: ; notranslate">var
  i: integer;
  lPropInfo: PPropInfo;
  lPropCount: integer;
  lPropList: PPropList;
  lPropType: PPTypeInfo;
begin
  lPropCount := GetPropList(PTypeInfo(AObject.ClassInfo), lPropList);
  for i := 0 to lPropCount - 1 do
  begin
   lPropInfo := lPropList^&#x5B;i];
    lPropType := lPropInfo^.PropType;
    if lPropType^.Kind = tkMethod then
    Continue;
  // ... processing of the properties ...
  end;
end;</pre>
<p>What other Kind of information is present in the list? Bellow is full definition of the type</p>
<pre class="brush: delphi; title: ; notranslate">type
  TTypeKind = (tkUnknown, tkInteger, tkChar, tkEnumeration,
tkFloat, tkString, tkSet, tkClass, tkMethod, tkWChar,
tkLString, tkWString, tkVariant, tkArray, tkRecord,
tkInterface, tkInt64, tkDynArray);
</pre>
<p>Now you are ready to get or set the value of the property:</p>
<pre class="brush: delphi; title: ; notranslate">function GetPropValue(Instance: TObject; const PropName: string;
  PreferStrings: Boolean = True): Variant;</pre>
<pre class="brush: delphi; title: ; notranslate">procedure SetPropValue(Instance: TObject; const PropName: string;
  const Value: Variant);</pre>
<p>And now you are ready to serialize your object, store it, load definition and deserialize an object back. And it could be not necessarily the same object.<br />
You would have to loop through the properties, read the values, and store it as an XML for later use.</p>
<p>I am not going to go through all specific details in this post, instead, you can find a full code for XML Class serializer <a href="http://www.dragonsoft.us/delphi_vcl.php" target="_blank">here</a>.</p>
<hr/><span style="font-size: 7pt">Copyright &copy; 2026 <strong><a href="https://blog.dragonsoft.us">Dragonsoft Technology View</a></strong>. This Feed is for personal non-commercial use only.</span><p>The post <a href="https://blog.dragonsoft.us/2008/04/21/how-to-serialize-delphi-object/">How to serialize Delphi object</a> appeared first on <a href="https://blog.dragonsoft.us">Dragonsoft Technology View</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.dragonsoft.us/2008/04/21/how-to-serialize-delphi-object/feed/</wfw:commentRss>
			<slash:comments>21</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">170</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Minified using Disk
Database Caching 22/85 queries in 0.071 seconds using Disk

Served from: blog.dragonsoft.us @ 2026-04-28 13:37:30 by W3 Total Cache
-->