<?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>From Zero To One &#187; Coding</title>
	<atom:link href="http://www.cromis.net/blog/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cromis.net/blog</link>
	<description>A blog about Delphi programming and all things technical</description>
	<lastBuildDate>Mon, 25 Jul 2011 19:27:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>How to make a very small windows service executable</title>
		<link>http://www.cromis.net/blog/2011/04/how-to-make-a-very-small-windows-service-executable/</link>
		<comments>http://www.cromis.net/blog/2011/04/how-to-make-a-very-small-windows-service-executable/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 15:51:19 +0000</pubDate>
		<dc:creator>Iztok Kacin</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.cromis.net/blog/?p=849</guid>
		<description><![CDATA[I a recent stack overflow question, a user asked how to make a Delphi generated NT Service executable smaller. There was some debate, if Delphi was appropriate to do this and if the executable size it generates was to big. Let me answer those two question as I see them: The size is not to [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">I a recent stack overflow <a title="Tiny NT Service executable" href="http://stackoverflow.com/questions/5561919/create-a-small-and-concise-windows-service-using-delphi">question</a>, a user asked how to make a Delphi generated NT Service executable smaller. There was some debate, if Delphi was appropriate to do this and if the executable size it generates was to big. Let me answer those two question as I see them:</p>
<ol>
<li style="text-align: justify;">The size is not to big. In today desktop environment a megabyte, or few of them don&#8217;t matter. The difference between 50K and 1MB executable just doesn&#8217;t matter. There is enough RAM and hard drive space, that very few situations need a smaller executable.</li>
<li>And in cases when you need that, you can get to that in Delphi. You don&#8217;t need C/C++. Sure you can make the same result there, but why? Even if you only use API calls, you can still reuse some of the low level code you have written in Delphi. And that is a good enough reason to do it in your known IDE and language. You already know your tool and can save a lot of time not writing support code you already have written.</li>
</ol>
<p>Ok, so I dusted off a very old example I made years back and recompiled it with the Delphi 2006 and Delphi XE compiler. (I have those currently at hand). The result are:</p>
<ul>
<li>Delphi 2006: 526 KB</li>
<li>Delphi XE: 1018 KB</li>
</ul>
<p>These are the result of opening a new service application and just clicking build. No settings were adjusted. Then I cleaned that old example a little removed the unneeded code and made sure it works (I tested the service). The results were the following:</p>
<ul>
<li>Delphi 2006: 22 KB</li>
<li>Delphi XE: 32 KB</li>
</ul>
<p style="text-align: justify;"><del>Here I striped XE version of RTTI as suggested on stack overflow</del> (actually as there is only procedural code the RTTI has no effect whatsoever on the code as noticed by Cris). I left the Delphi 2006 intact. The code I used is posted bellow. It is basically a service skeleton made of two parts. One is the part that installs and controls the service. And the other is the service code itself that spawns a new &#8220;service control manager&#8221; attached process and then just waits until it is told to stop. It also reports the status to SCM.</p>
<p style="text-align: justify;">And now the challenge. How small can you make a static linked, single c/c++ executable service. It would be fun to know. I will play more with this latter trying different compiler settings and other tricks to see it I can squeeze a byte or two out of my current size <img src='http://www.cromis.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>A word of advice. Do not just copy and paste the sample service skeleton. It is just a prototype to show what can be done. It is in no way complete and does not have good error coverage. If enough people finds it important I can finish the code and polish it, but otherwise it is not worth the time.</p>

<div class="wp_syntax"><div class="code"><pre class="delphi" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">{
  NT Service  model based completely on API calls. Version 0.1
  Inspired by NT service skeleton from Aphex
  Adapted by Runner
}</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">program</span> PureAPIService<span style="color: #000066;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">{$APPTYPE CONSOLE}</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">uses</span>
  Windows<span style="color: #000066;">,</span>
  WinSvc<span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">const</span>
  ServiceName     <span style="color: #000066;">=</span> <span style="color: #ff0000;">'PureAPIService'</span><span style="color: #000066;">;</span>
  DisplayName     <span style="color: #000066;">=</span> <span style="color: #ff0000;">'Pure Windows API Service'</span><span style="color: #000066;">;</span>
  NUM_OF_SERVICES <span style="color: #000066;">=</span> <span style="color: #0000ff;">2</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span>
  ServiceStatus <span style="color: #000066;">:</span> TServiceStatus<span style="color: #000066;">;</span>
  StatusHandle  <span style="color: #000066;">:</span> SERVICE_STATUS_HANDLE<span style="color: #000066;">;</span>
  ServiceTable  <span style="color: #000066;">:</span> <span style="color: #000000; font-weight: bold;">array</span> <span style="color: #000066;">&#91;</span><span style="color: #0000ff;">0</span><span style="color: #000066;">..</span><span style="color: #006600;">NUM_OF_SERVICES</span><span style="color: #000066;">&#93;</span> <span style="color: #000000; font-weight: bold;">of</span> TServiceTableEntry<span style="color: #000066;">;</span>
  Stopped       <span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Boolean</span><span style="color: #000066;">;</span>
  Paused        <span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Boolean</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span>
  ghSvcStopEvent<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Cardinal</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> OnServiceCreate<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  <span style="color: #808080; font-style: italic;">// do your stuff here;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> AfterUninstall<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  <span style="color: #808080; font-style: italic;">// do your stuff here;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> ReportSvcStatus<span style="color: #000066;">&#40;</span>dwCurrentState<span style="color: #000066;">,</span> dwWin32ExitCode<span style="color: #000066;">,</span> dwWaitHint<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">DWORD</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  <span style="color: #808080; font-style: italic;">// fill in the SERVICE_STATUS structure.</span>
  ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwCurrentState</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> dwCurrentState<span style="color: #000066;">;</span>
  ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwWin32ExitCode</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> dwWin32ExitCode<span style="color: #000066;">;</span>
  ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwWaitHint</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> dwWaitHint<span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">case</span> dwCurrentState <span style="color: #000000; font-weight: bold;">of</span>
    SERVICE_START_PENDING<span style="color: #000066;">:</span> ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwControlsAccepted</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">0</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">else</span>
      ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwControlsAccepted</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> SERVICE_ACCEPT_STOP<span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #000066;">&#40;</span>dwCurrentState <span style="color: #000066;">=</span> SERVICE_RUNNING<span style="color: #000066;">&#41;</span> <span style="color: #000000; font-weight: bold;">or</span> <span style="color: #000066;">&#40;</span>dwCurrentState <span style="color: #000066;">=</span> SERVICE_STOPPED<span style="color: #000066;">&#41;</span> <span style="color: #000000; font-weight: bold;">of</span>
    <span style="color: #000000; font-weight: bold;">True</span><span style="color: #000066;">:</span> ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwCheckPoint</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">0</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">False</span><span style="color: #000066;">:</span> ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwCheckPoint</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">1</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">// Report the status of the service to the SCM.</span>
  SetServiceStatus<span style="color: #000066;">&#40;</span>StatusHandle<span style="color: #000066;">,</span> ServiceStatus<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> MainProc<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  <span style="color: #808080; font-style: italic;">// we have to do something or service will stop</span>
  ghSvcStopEvent <span style="color: #000066;">:</span><span style="color: #000066;">=</span> CreateEvent<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">nil</span><span style="color: #000066;">,</span> <span style="color: #000000; font-weight: bold;">True</span><span style="color: #000066;">,</span> <span style="color: #000000; font-weight: bold;">False</span><span style="color: #000066;">,</span> <span style="color: #000000; font-weight: bold;">nil</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> ghSvcStopEvent <span style="color: #000066;">=</span> <span style="color: #0000ff;">0</span> <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #000000; font-weight: bold;">begin</span>
    ReportSvcStatus<span style="color: #000066;">&#40;</span>SERVICE_STOPPED<span style="color: #000066;">,</span> NO_ERROR<span style="color: #000066;">,</span> <span style="color: #0000ff;">0</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000066;">Exit</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">// Report running status when initialization is complete.</span>
  ReportSvcStatus<span style="color: #000066;">&#40;</span> SERVICE_RUNNING<span style="color: #000066;">,</span> NO_ERROR<span style="color: #000066;">,</span> <span style="color: #0000ff;">0</span> <span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">// Perform work until service stops.</span>
  <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #000000; font-weight: bold;">True</span> <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">begin</span>
    <span style="color: #808080; font-style: italic;">// Check whether to stop the service.</span>
    WaitForSingleObject<span style="color: #000066;">&#40;</span>ghSvcStopEvent<span style="color: #000066;">,</span> INFINITE<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    ReportSvcStatus<span style="color: #000066;">&#40;</span>SERVICE_STOPPED<span style="color: #000066;">,</span> NO_ERROR<span style="color: #000066;">,</span> <span style="color: #0000ff;">0</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000066;">Exit</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> ServiceCtrlHandler<span style="color: #000066;">&#40;</span>Control<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">DWORD</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span> <span style="color: #000000; font-weight: bold;">stdcall</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  <span style="color: #000000; font-weight: bold;">case</span> Control <span style="color: #000000; font-weight: bold;">of</span>
    SERVICE_CONTROL_STOP<span style="color: #000066;">:</span>
      <span style="color: #000000; font-weight: bold;">begin</span>
        Stopped <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000000; font-weight: bold;">True</span><span style="color: #000066;">;</span>
        SetEvent<span style="color: #000066;">&#40;</span>ghSvcStopEvent<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
        ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwCurrentState</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> SERVICE_STOP_PENDING<span style="color: #000066;">;</span>
        SetServiceStatus<span style="color: #000066;">&#40;</span>StatusHandle<span style="color: #000066;">,</span> ServiceStatus<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
      <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
    SERVICE_CONTROL_PAUSE<span style="color: #000066;">:</span>
      <span style="color: #000000; font-weight: bold;">begin</span>
        Paused <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000000; font-weight: bold;">True</span><span style="color: #000066;">;</span>
        ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwcurrentstate</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> SERVICE_PAUSED<span style="color: #000066;">;</span>
        SetServiceStatus<span style="color: #000066;">&#40;</span>StatusHandle<span style="color: #000066;">,</span> ServiceStatus<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
      <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
    SERVICE_CONTROL_CONTINUE<span style="color: #000066;">:</span>
      <span style="color: #000000; font-weight: bold;">begin</span>
        Paused <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000000; font-weight: bold;">False</span><span style="color: #000066;">;</span>
        ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwCurrentState</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> SERVICE_RUNNING<span style="color: #000066;">;</span>
        SetServiceStatus<span style="color: #000066;">&#40;</span>StatusHandle<span style="color: #000066;">,</span> ServiceStatus<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
      <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
    SERVICE_CONTROL_INTERROGATE<span style="color: #000066;">:</span> SetServiceStatus<span style="color: #000066;">&#40;</span>StatusHandle<span style="color: #000066;">,</span> ServiceStatus<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    SERVICE_CONTROL_SHUTDOWN<span style="color: #000066;">:</span> Stopped <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000000; font-weight: bold;">True</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> RegisterService<span style="color: #000066;">&#40;</span>dwArgc<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">DWORD</span><span style="color: #000066;">;</span> <span style="color: #000000; font-weight: bold;">var</span> lpszArgv<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">PChar</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span> <span style="color: #000000; font-weight: bold;">stdcall</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwServiceType</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> SERVICE_WIN32_OWN_PROCESS<span style="color: #000066;">;</span>
  ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwCurrentState</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> SERVICE_START_PENDING<span style="color: #000066;">;</span>
  ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwControlsAccepted</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> SERVICE_ACCEPT_STOP <span style="color: #000000; font-weight: bold;">or</span> SERVICE_ACCEPT_PAUSE_CONTINUE<span style="color: #000066;">;</span>
  ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwServiceSpecificExitCode</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">0</span><span style="color: #000066;">;</span>
  ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwWin32ExitCode</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">0</span><span style="color: #000066;">;</span>
  ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwCheckPoint</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">0</span><span style="color: #000066;">;</span>
  ServiceStatus<span style="color: #000066;">.</span><span style="color: #006600;">dwWaitHint</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">0</span><span style="color: #000066;">;</span>
&nbsp;
  StatusHandle <span style="color: #000066;">:</span><span style="color: #000066;">=</span> RegisterServiceCtrlHandler<span style="color: #000066;">&#40;</span>ServiceName<span style="color: #000066;">,</span> <span style="color: #000066;">@</span>ServiceCtrlHandler<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> StatusHandle &lt;&gt; <span style="color: #0000ff;">0</span> <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #000000; font-weight: bold;">begin</span>
    ReportSvcStatus<span style="color: #000066;">&#40;</span>SERVICE_RUNNING<span style="color: #000066;">,</span> NO_ERROR<span style="color: #000066;">,</span> <span style="color: #0000ff;">0</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">try</span>
      Stopped <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000000; font-weight: bold;">False</span><span style="color: #000066;">;</span>
      Paused  <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000000; font-weight: bold;">False</span><span style="color: #000066;">;</span>
      MainProc<span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">finally</span>
      ReportSvcStatus<span style="color: #000066;">&#40;</span>SERVICE_STOPPED<span style="color: #000066;">,</span> NO_ERROR<span style="color: #000066;">,</span> <span style="color: #0000ff;">0</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> UninstallService<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> ServiceName<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">PChar</span><span style="color: #000066;">;</span> <span style="color: #000000; font-weight: bold;">const</span> Silent<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Boolean</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">const</span>
  cRemoveMsg <span style="color: #000066;">=</span> <span style="color: #ff0000;">'Your service was removed sucesfuly!'</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">var</span>
  SCManager<span style="color: #000066;">:</span> SC_HANDLE<span style="color: #000066;">;</span>
  Service<span style="color: #000066;">:</span> SC_HANDLE<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  SCManager <span style="color: #000066;">:</span><span style="color: #000066;">=</span> OpenSCManager<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">nil</span><span style="color: #000066;">,</span> <span style="color: #000000; font-weight: bold;">nil</span><span style="color: #000066;">,</span> SC_MANAGER_ALL_ACCESS<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">if</span> SCManager <span style="color: #000066;">=</span> <span style="color: #0000ff;">0</span> <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000066;">Exit</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">try</span>
    Service <span style="color: #000066;">:</span><span style="color: #000066;">=</span> OpenService<span style="color: #000066;">&#40;</span>SCManager<span style="color: #000066;">,</span> ServiceName<span style="color: #000066;">,</span> SERVICE_ALL_ACCESS<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    ControlService<span style="color: #000066;">&#40;</span>Service<span style="color: #000066;">,</span> SERVICE_CONTROL_STOP<span style="color: #000066;">,</span> ServiceStatus<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    DeleteService<span style="color: #000066;">&#40;</span>Service<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    CloseServiceHandle<span style="color: #000066;">&#40;</span>Service<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">not</span> Silent <span style="color: #000000; font-weight: bold;">then</span>
      MessageBox<span style="color: #000066;">&#40;</span><span style="color: #0000ff;">0</span><span style="color: #000066;">,</span> cRemoveMsg<span style="color: #000066;">,</span> ServiceName<span style="color: #000066;">,</span> MB_ICONINFORMATION <span style="color: #000000; font-weight: bold;">or</span> MB_OK <span style="color: #000000; font-weight: bold;">or</span> MB_TASKMODAL <span style="color: #000000; font-weight: bold;">or</span> MB_TOPMOST<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">finally</span>
    CloseServiceHandle<span style="color: #000066;">&#40;</span>SCManager<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    AfterUninstall<span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> InstallService<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> ServiceName<span style="color: #000066;">,</span> DisplayName<span style="color: #000066;">,</span> LoadOrder<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">PChar</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">const</span> FileName<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span> <span style="color: #000000; font-weight: bold;">const</span> Silent<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Boolean</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">const</span>
  cInstallMsg <span style="color: #000066;">=</span> <span style="color: #ff0000;">'Your service was Installed sucesfuly!'</span><span style="color: #000066;">;</span>
  cSCMError <span style="color: #000066;">=</span> <span style="color: #ff0000;">'Error trying to open SC Manager'</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">var</span>
  SCMHandle  <span style="color: #000066;">:</span> SC_HANDLE<span style="color: #000066;">;</span>
  SvHandle   <span style="color: #000066;">:</span> SC_HANDLE<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  SCMHandle <span style="color: #000066;">:</span><span style="color: #000066;">=</span> OpenSCManager<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">nil</span><span style="color: #000066;">,</span> <span style="color: #000000; font-weight: bold;">nil</span><span style="color: #000066;">,</span> SC_MANAGER_ALL_ACCESS<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> SCMHandle <span style="color: #000066;">=</span> <span style="color: #0000ff;">0</span> <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #000000; font-weight: bold;">begin</span>
    MessageBox<span style="color: #000066;">&#40;</span><span style="color: #0000ff;">0</span><span style="color: #000066;">,</span> cSCMError<span style="color: #000066;">,</span> ServiceName<span style="color: #000066;">,</span> MB_ICONERROR <span style="color: #000000; font-weight: bold;">or</span> MB_OK <span style="color: #000000; font-weight: bold;">or</span> MB_TASKMODAL <span style="color: #000000; font-weight: bold;">or</span> MB_TOPMOST<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000066;">Exit</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">try</span>
    SvHandle <span style="color: #000066;">:</span><span style="color: #000066;">=</span> CreateService<span style="color: #000066;">&#40;</span>SCMHandle<span style="color: #000066;">,</span>
                              ServiceName<span style="color: #000066;">,</span>
                              DisplayName<span style="color: #000066;">,</span>
                              SERVICE_ALL_ACCESS<span style="color: #000066;">,</span>
                              SERVICE_WIN32_OWN_PROCESS<span style="color: #000066;">,</span>
                              SERVICE_AUTO_START<span style="color: #000066;">,</span>
                              SERVICE_ERROR_IGNORE<span style="color: #000066;">,</span>
                              <span style="color: #000066; font-weight: bold;">pchar</span><span style="color: #000066;">&#40;</span>FileName<span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
                              LoadOrder<span style="color: #000066;">,</span>
                              <span style="color: #000000; font-weight: bold;">nil</span><span style="color: #000066;">,</span>
                              <span style="color: #000000; font-weight: bold;">nil</span><span style="color: #000066;">,</span>
                              <span style="color: #000000; font-weight: bold;">nil</span><span style="color: #000066;">,</span>
                              <span style="color: #000000; font-weight: bold;">nil</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    CloseServiceHandle<span style="color: #000066;">&#40;</span>SvHandle<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">not</span> Silent <span style="color: #000000; font-weight: bold;">then</span>
      MessageBox<span style="color: #000066;">&#40;</span><span style="color: #0000ff;">0</span><span style="color: #000066;">,</span> cInstallMsg<span style="color: #000066;">,</span> ServiceName<span style="color: #000066;">,</span> MB_ICONINFORMATION <span style="color: #000000; font-weight: bold;">or</span> MB_OK <span style="color: #000000; font-weight: bold;">or</span> MB_TASKMODAL <span style="color: #000000; font-weight: bold;">or</span> MB_TOPMOST<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">finally</span>
    CloseServiceHandle<span style="color: #000066;">&#40;</span>SCMHandle<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> WriteHelpContent<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  <span style="color: #000066;">WriteLn</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'To install your service please type  /install'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">WriteLn</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'To uninstall your service please type  /remove'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">WriteLn</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'For help please type  /? or /h'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">begin</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000066;">&#40;</span><span style="color: #000066;">ParamStr</span><span style="color: #000066;">&#40;</span><span style="color: #0000ff;">1</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> <span style="color: #ff0000;">'/h'</span><span style="color: #000066;">&#41;</span> <span style="color: #000000; font-weight: bold;">or</span> <span style="color: #000066;">&#40;</span><span style="color: #000066;">ParamStr</span><span style="color: #000066;">&#40;</span><span style="color: #0000ff;">1</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> <span style="color: #ff0000;">'/?'</span><span style="color: #000066;">&#41;</span> <span style="color: #000000; font-weight: bold;">then</span>
    WriteHelpContent
  <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000066;">ParamStr</span><span style="color: #000066;">&#40;</span><span style="color: #0000ff;">1</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> <span style="color: #ff0000;">'/install'</span> <span style="color: #000000; font-weight: bold;">then</span>
    InstallService<span style="color: #000066;">&#40;</span>ServiceName<span style="color: #000066;">,</span> DisplayName<span style="color: #000066;">,</span> <span style="color: #ff0000;">'System Reserved'</span><span style="color: #000066;">,</span> <span style="color: #000066;">ParamStr</span><span style="color: #000066;">&#40;</span><span style="color: #0000ff;">0</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span> <span style="color: #000066;">ParamStr</span><span style="color: #000066;">&#40;</span><span style="color: #0000ff;">2</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> <span style="color: #ff0000;">'/s'</span><span style="color: #000066;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000066;">ParamStr</span><span style="color: #000066;">&#40;</span><span style="color: #0000ff;">1</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> <span style="color: #ff0000;">'/remove'</span> <span style="color: #000000; font-weight: bold;">then</span>
    UninstallService<span style="color: #000066;">&#40;</span>ServiceName<span style="color: #000066;">,</span> <span style="color: #000066;">ParamStr</span><span style="color: #000066;">&#40;</span><span style="color: #0000ff;">2</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> <span style="color: #ff0000;">'/s'</span><span style="color: #000066;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000066;">ParamCount</span> <span style="color: #000066;">=</span> <span style="color: #0000ff;">0</span> <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #000000; font-weight: bold;">begin</span>
    OnServiceCreate<span style="color: #000066;">;</span>
&nbsp;
    ServiceTable<span style="color: #000066;">&#91;</span><span style="color: #0000ff;">0</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">.</span><span style="color: #006600;">lpServiceName</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> ServiceName<span style="color: #000066;">;</span>
    ServiceTable<span style="color: #000066;">&#91;</span><span style="color: #0000ff;">0</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">.</span><span style="color: #006600;">lpServiceProc</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">@</span>RegisterService<span style="color: #000066;">;</span>
    ServiceTable<span style="color: #000066;">&#91;</span><span style="color: #0000ff;">1</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">.</span><span style="color: #006600;">lpServiceName</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000000; font-weight: bold;">nil</span><span style="color: #000066;">;</span>
    ServiceTable<span style="color: #000066;">&#91;</span><span style="color: #0000ff;">1</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">.</span><span style="color: #006600;">lpServiceProc</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000000; font-weight: bold;">nil</span><span style="color: #000066;">;</span>
&nbsp;
    StartServiceCtrlDispatcher<span style="color: #000066;">&#40;</span>ServiceTable<span style="color: #000066;">&#91;</span><span style="color: #0000ff;">0</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span>
  <span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #000066;">WriteLn</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Wrong argument!'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">.</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.cromis.net/blog/2011/04/how-to-make-a-very-small-windows-service-executable/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Contact on the blog</title>
		<link>http://www.cromis.net/blog/2011/03/contant-on-the-blog/</link>
		<comments>http://www.cromis.net/blog/2011/03/contant-on-the-blog/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 21:52:17 +0000</pubDate>
		<dc:creator>Iztok Kacin</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.cromis.net/blog/?p=844</guid>
		<description><![CDATA[If you tried to contact me via the contact page in the last few days, I was not reachable. The reason is, that I changed my gmail account password and forgot to change it in wordpress SMTP plugin. So if you did not receive a response, please try again and sorry for the inconvenience.]]></description>
			<content:encoded><![CDATA[<p>If you tried to contact me via the contact page in the last few days, I was not reachable. The reason is, that I changed my gmail account password and forgot to change it in wordpress SMTP plugin. So if you did not receive a response, please try again and sorry for the inconvenience.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cromis.net/blog/2011/03/contant-on-the-blog/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>New version of SimpleStorage and other updates</title>
		<link>http://www.cromis.net/blog/2011/03/new-version-of-simplestorage-and-other-updates/</link>
		<comments>http://www.cromis.net/blog/2011/03/new-version-of-simplestorage-and-other-updates/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 19:33:56 +0000</pubDate>
		<dc:creator>Iztok Kacin</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.cromis.net/blog/?p=807</guid>
		<description><![CDATA[Quite a lot of new code got piled up so without further ado here are the news. (You can get all new releases from the download page) SimpleStorage This a new major release (1.7.3) of SimpleStorage. And sadly also a breaking one. At least if you were writing your own filters and adapters. There was [...]]]></description>
			<content:encoded><![CDATA[<p>Quite a lot of new code got piled up so without further ado here are the news.</p>
<p>(You can get all new releases from the download page)</p>
<h3><span style="font-weight: normal;"><span></p>
<h3 style="font-size: 1.17em;">SimpleStorage</h3>
<p></span></span></h3>
<p style="text-align: justify;">This a new major release (1.7.3) of SimpleStorage. And sadly also a breaking one. At least if you were writing your own filters and adapters. There was no other way around if I wanted to write a good and clean code. All changes that were made revolve around filters and adapters. Here is the list of important changes</p>
<ul>
<li>Filters were extended to the document level. This means you can now compress and encrypt XML nodes or whole document in a transparent manner.</li>
<li>Chaining was introduced to filters. This means you can now encrypt and compress a document in a single step or if you like, in a single line of code <img src='http://www.cromis.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>Encryption and compression are now integral part of SimpleStorage and no third party components are needed anymore.</li>
<li>Adapters and Filter now use cleaner approach, so no more strings as identifiers, to specify which filter or adapter you want.</li>
</ul>
<p>Let me give you some examples:</p>
<p>Compressing and the encrypting a whole document.</p>

<div class="wp_syntax"><div class="code"><pre class="delphi" style="font-family:monospace;">NormalXML<span style="color: #000066;">.</span><span style="color: #006600;">Filter</span><span style="color: #000066;">&#40;</span>ZLIB<span style="color: #000066;">&#41;</span><span style="color: #000066;">.</span><span style="color: #006600;">Filter</span><span style="color: #000066;">&#40;</span>XTEA<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'MyStrongKey'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">.</span><span style="color: #006600;">SaveToFile</span><span style="color: #000066;">&#40;</span>FilteredXMLFileTwo<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span></pre></div></div>

<p>The same but using a document fiter chain interface.</p>

<div class="wp_syntax"><div class="code"><pre class="delphi" style="font-family:monospace;">DocumentFilterChain <span style="color: #000066;">:</span><span style="color: #000066;">=</span> CreateDocumentFilterChain<span style="color: #000066;">;</span>
DocumentFilterChain<span style="color: #000066;">.</span><span style="color: #006600;">AddFilter</span><span style="color: #000066;">&#40;</span>CompressedStorage<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
DocumentFilterChain<span style="color: #000066;">.</span><span style="color: #006600;">AddFilter</span><span style="color: #000066;">&#40;</span>EncryptedStorage<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'MyStrongKey'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
NormalXML <span style="color: #000066;">:</span><span style="color: #000066;">=</span> DocumentFilterChain<span style="color: #000066;">.</span><span style="color: #006600;">LoadFromFile</span><span style="color: #000066;">&#40;</span>FilteredXMLFileOne<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
NormalXML<span style="color: #000066;">.</span><span style="color: #006600;">SaveToFile</span><span style="color: #000066;">&#40;</span>NormalXMLFileOne<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span></pre></div></div>

<p>Compressing using the compressed storage interface.</p>

<div class="wp_syntax"><div class="code"><pre class="delphi" style="font-family:monospace;">CompressedStorage<span style="color: #000066;">.</span><span style="color: #006600;">SaveToFile</span><span style="color: #000066;">&#40;</span>DecompressedXML<span style="color: #000066;">,</span> CompressedXMLFileOne<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span></pre></div></div>

<p>Compressing using the build in ZLIB filter.</p>

<div class="wp_syntax"><div class="code"><pre class="delphi" style="font-family:monospace;">DecompressedXML<span style="color: #000066;">.</span><span style="color: #006600;">Filter</span><span style="color: #000066;">&#40;</span>ZLIB<span style="color: #000066;">&#41;</span><span style="color: #000066;">.</span><span style="color: #006600;">SaveToFile</span><span style="color: #000066;">&#40;</span>CompressedXMLFileTwo<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span></pre></div></div>

<p>Do you see how simple it is to compress and encrypt a XML document. The other change is in the adapter code. There are no more strings to specify which adapter to use. It looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="delphi" style="font-family:monospace;">  SS<span style="color: #000066;">.</span><span style="color: #006600;">Ensure</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'MemTable'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">.</span><span style="color: #006600;">Adapter</span><span style="color: #000066;">&#40;</span>DataSet<span style="color: #000066;">&#41;</span><span style="color: #000066;">.</span><span style="color: #006600;">Load</span><span style="color: #000066;">&#40;</span>ClientDS<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span></pre></div></div>

<p>and</p>

<div class="wp_syntax"><div class="code"><pre class="delphi" style="font-family:monospace;">  SS<span style="color: #000066;">.</span><span style="color: #006600;">Get</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'MemTable'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">.</span><span style="color: #006600;">Adapter</span><span style="color: #000066;">&#40;</span>DataSet<span style="color: #000066;">&#41;</span><span style="color: #000066;">.</span><span style="color: #006600;">Save</span><span style="color: #000066;">&#40;</span>ClientDS<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span></pre></div></div>

<p style="text-align: justify;">There are other smaller changes, but this are the major ones. Just a warning here. If you were writing adapters or filters (your own) then this is a breaking release and you will have to update your code to the new specifications. The examples that come withe the library are clear enough that it should be a breeze. For normal user nothing changes and the code will stay the same. I also left the old version of SimpleStorage available for download if people don&#8217;t want to upgrade right away.</p>
<p style="text-align: justify;">Also I would like to announce that I will begin writing basic documentation for SimpleStorage.</p>
<h3>ISAPIServer</h3>
<p style="text-align: justify;">This is a new component in the library. It is a standalone ISAPI server capable of processing Delphi ISAPI modules. You don&#8217;t need Apache or IIS. And it is build in the way, that you can use your favorite HTTP library to use it. It comes with already made bindings for Indy, but it would be equally simple to do bindings for Synapse or ICS. This is possible because it is designed in a very modular way. If any of you are interested in that, you can contact me and I can help with it. I am posting the whole ISAPI request code for Indy as an example:</p>

<div class="wp_syntax"><div class="code"><pre class="delphi" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">procedure</span> TfMain<span style="color: #000066;">.</span><span style="color: #006600;">HTTPServerCommandGet</span><span style="color: #000066;">&#40;</span><span style="color: #008000; font-style: italic;">{$IFDEF Indy9}</span>
                                        AThread<span style="color: #000066;">:</span> TIdPeerThread<span style="color: #000066;">;</span>
                                      <span style="color: #008000; font-style: italic;">{$ELSE}</span>
                                        AContext<span style="color: #000066;">:</span> TIdContext<span style="color: #000066;">;</span>
                                      <span style="color: #008000; font-style: italic;">{$ENDIF}</span>
                                      ARequestInfo<span style="color: #000066;">:</span> TIdHTTPRequestInfo<span style="color: #000066;">;</span>
                                      AResponseInfo<span style="color: #000066;">:</span> TIdHTTPResponseInfo<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">var</span>
  ECB<span style="color: #000066;">:</span> TECBData<span style="color: #000066;">;</span>
  Port<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
  TempStr<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
  PathStr<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
  RootDir<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
  DDLFileName<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  TempStr <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">Copy</span><span style="color: #000066;">&#40;</span>ARequestInfo<span style="color: #000066;">.</span><span style="color: #006600;">Document</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">2</span><span style="color: #000066;">,</span> <span style="color: #000066;">Length</span><span style="color: #000066;">&#40;</span>ARequestInfo<span style="color: #000066;">.</span><span style="color: #006600;">Document</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  RootDir <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">IncludeTrailingPathDelimiter</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">ExtractFilePath</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">ParamStr</span><span style="color: #000066;">&#40;</span><span style="color: #0000ff;">0</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  PathStr <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #ff0000;">'/'</span> <span style="color: #000066;">+</span> StrAfter<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'/'</span><span style="color: #000066;">,</span> TempStr<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  DDLFileName <span style="color: #000066;">:</span><span style="color: #000066;">=</span> StrBefore<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'/'</span><span style="color: #000066;">,</span> TempStr<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #008000; font-style: italic;">{$IFDEF Indy9}</span>
    Port <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">IntToStr</span><span style="color: #000066;">&#40;</span>AThread<span style="color: #000066;">.</span><span style="color: #006600;">Connection</span><span style="color: #000066;">.</span><span style="color: #006600;">Socket</span><span style="color: #000066;">.</span><span style="color: #006600;">Binding</span><span style="color: #000066;">.</span><span style="color: #006600;">Port</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #008000; font-style: italic;">{$ELSE}</span>
    Port <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">IntToStr</span><span style="color: #000066;">&#40;</span>AContext<span style="color: #000066;">.</span><span style="color: #006600;">Binding</span><span style="color: #000066;">.</span><span style="color: #006600;">Port</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #008000; font-style: italic;">{$ENDIF}</span>
&nbsp;
  ECB <span style="color: #000066;">:</span><span style="color: #000066;">=</span> ECBDataList<span style="color: #000066;">.</span><span style="color: #006600;">AcquireNewECB</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">try</span>
    FillECBFromRequest<span style="color: #000066;">&#40;</span>ECB<span style="color: #000066;">,</span> HTTPServer<span style="color: #000066;">.</span><span style="color: #006600;">KeepAlive</span><span style="color: #000066;">,</span> ARequestInfo<span style="color: #000066;">,</span> RootDir<span style="color: #000066;">,</span> DDLFileName<span style="color: #000066;">,</span> Port<span style="color: #000066;">,</span> PathStr<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">try</span>
      FISAPIServer<span style="color: #000066;">.</span><span style="color: #006600;">Execute</span><span style="color: #000066;">&#40;</span>DDLFileName<span style="color: #000066;">,</span> ECB<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">finally</span>
      FillResponseFromECB<span style="color: #000066;">&#40;</span>ECB<span style="color: #000066;">,</span> AResponseInfo<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">finally</span>
    ECBDataList<span style="color: #000066;">.</span><span style="color: #006600;">DeleteECB</span><span style="color: #000066;">&#40;</span>ECB<span style="color: #000066;">.</span><span style="color: #006600;">ECB</span><span style="color: #000066;">.</span><span style="color: #006600;">ConnID</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span></pre></div></div>

<h3>RoboMailer</h3>
<p style="text-align: justify;">This is also a new component. It is intended as a simplified mass mailer component. It can also be used to send a single mail easily with no worries on how to set everything up correctly. It comes with a demo application, which can send mass mails. You can personify each mail with the data you provide.  Maybe it will be of use to somebody. It uses ICS as an engine.</p>
<h3>Threading unit</h3>
<p style="text-align: justify;">This unit got two interesting additions. First one is a lock free stack based on the windows API. No home made code here, just a wrapper around windows API. And the second one is a thread safe queue. It uses critical sections but tries to lock as little as possible. I have done some tests and it is very fast. In fact it is almost as fast as a lock free one, but the code is much much simpler. There is very little difference in speed in fact it is negligible in real world problems.</p>
<p>ChangleLog:</p>
<ul>
<li>1.4.0
<ul>
<li>Added TLockFreeStack based on Windows SLISTS</li>
<li>Added TThreadSafeQueue based on linked lists</li>
</ul>
</li>
<li>1.3.7
<ul>
<li>Added ShutdownTimeout (INFINITE by default)</li>
<li>Wait for all tasks to finish then shutting down the task pool</li>
</ul>
</li>
</ul>
<h3>CRON Scheduler</h3>
<p><span style="font-weight: normal;">Change Log:</span></p>
<ul>
<li>2.0.3
<ul>
<li>added HasValue function for TChronEntry</li>
</ul>
</li>
</ul>
<div id="_mcePaste">
<h3 style="font-size: 1.17em;">SimpleLog</h3>
</div>
<p><span style="font-weight: normal;">Change Log:</span></p>
<ul>
<li>1.2.0
<ul>
<li>Use the new rewritten Cromis.Exceptions</li>
<li>Log file limit is now working correctly</li>
</ul>
</li>
</ul>
<div id="_mcePaste">
<h3 style="font-size: 1.17em;">XTEA</h3>
</div>
<div id="_mcePaste">
<p><span style="font-weight: normal;">Change Log:</span></p>
<ul>
<li>1.1.0
<ul>
<li>Added overloaded procedures for stream and file encryption / decryption</li>
</ul>
</li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cromis.net/blog/2011/03/new-version-of-simplestorage-and-other-updates/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>TValue and other &#8220;Variants&#8221; like implementation tests</title>
		<link>http://www.cromis.net/blog/2010/03/tvalue-and-other-variable-like-implementation-tests/</link>
		<comments>http://www.cromis.net/blog/2010/03/tvalue-and-other-variable-like-implementation-tests/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 11:51:30 +0000</pubDate>
		<dc:creator>Iztok Kacin</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.cromis.net/blog/?p=710</guid>
		<description><![CDATA[The recent post from Mason Wheeler about TValue speed was very interesting. I always had the impression, that variants were slow, but never tested that. So this was a surprise to me. But how fast the variants really are? There are other &#8220;variants&#8221; like implementations out there, so I decided to test them in a [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">The recent <a title="TValue is very slow" href="http://www.delphifeeds.com/go/s/66399">post</a> from Mason Wheeler about TValue speed was very interesting. I always had the impression, that variants were slow, but never tested that. So this was a surprise to me. But how fast the variants really are? There are other &#8220;variants&#8221; like implementations out there, so I decided to test them in a common test. At least the ones I know that exist. The record implicit operator allows for some very flexible operations on different data types. So I tested 5 different approaches to &#8220;variant&#8221; implementation.</p>
<ul>
<li>Variants (build in Delphi as long as I can remember <img src='http://www.cromis.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</li>
<li>TValue (new in Delphi 2010)</li>
<li>TAnyValue (recently added to my <a title="http://www.cromis.net/blog/downloads/" href="http://www.cromis.net/blog/downloads/">library</a>)</li>
<li>TOmniValue (part of <a title="OmniThreadLibrary" href="http://otl.17slon.com/">OmniThreadLibrary</a>)</li>
<li>Bare-bone variant record implementation for comparison.</li>
</ul>
<p style="text-align: justify;">Here is the code I tested on. It is just a little changed version of Masons. It forces the compiler to include all lines (by calling Writeln on resulting values) and it averages over integers, strings and floating point values. Just integers seemed unfair to me. After all in real life we would use all possible combinations of data. The test also has range and overflow checks turned on.</p>
<p><span style="text-decoration: underline;"><strong>The results:</strong></span></p>
<p>Iterations: <span style="text-decoration: underline;">10000000</span></p>
<p>Times are in milliseconds</p>
<table style="border-collapse: collapse; border-spacing: 0px;" border="1" cellpadding="3px" width="700px">
<tbody>
<tr>
<td><span style="color: #0000ff;"><strong>Type</strong></span></td>
<td><span style="color: #0000ff;"><strong>Variants</strong></span></td>
<td><span style="color: #0000ff;"><strong>TValue</strong></span></td>
<td><span style="color: #0000ff;"><strong>TAnyValue</strong></span></td>
<td><span style="color: #0000ff;"><strong>TOmniValue</strong></span></td>
<td><span style="color: #0000ff;"><strong>TVariableRec</strong></span></td>
</tr>
<tr>
<td style="padding-left: 5px;"><span style="color: #0000ff;">j := I</span></td>
<td style="text-align: center;">255</td>
<td style="text-align: center;">4070</td>
<td style="text-align: center;">916</td>
<td style="text-align: center;">128</td>
<td style="text-align: center;">175</td>
</tr>
<tr>
<td style="padding-left: 5px;"><span style="color: #0000ff;">j := I/5</span></td>
<td style="text-align: center;">332</td>
<td style="text-align: center;">4081</td>
<td style="text-align: center;">1400</td>
<td style="text-align: center;">3265</td>
<td style="text-align: center;">313</td>
</tr>
<tr>
<td style="padding-left: 5px;"><span style="color: #0000ff;">j := IntToStr(I)</span></td>
<td style="text-align: center;">4548</td>
<td style="text-align: center;">11051</td>
<td style="text-align: center;">7873</td>
<td style="text-align: center;">6429</td>
<td style="text-align: center;">2795</td>
</tr>
<tr>
<td style="padding-left: 5px;"><span style="color: #0000ff;">ALL</span></td>
<td style="text-align: center;">4905</td>
<td style="text-align: center;">18847</td>
<td style="text-align: center;">9932</td>
<td style="text-align: center;">9654</td>
<td style="text-align: center;">3255</td>
</tr>
</tbody>
</table>
<p><span style="text-decoration: underline;"><strong>And here is the test code:</strong></span></p>

<div class="wp_syntax"><div class="code"><pre class="delphi" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">program</span> ValuesTest<span style="color: #000066;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">{$APPTYPE CONSOLE}</span>
<span style="color: #000000; font-weight: bold;">uses</span>
  SysUtils<span style="color: #000066;">,</span>
  rtti<span style="color: #000066;">,</span>
  diagnostics<span style="color: #000066;">,</span>
  OtlCommon<span style="color: #000066;">,</span>
  Cromis<span style="color: #000066;">.</span><span style="color: #006600;">AnyValue</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">const</span>
  HUNDRED_MILLION <span style="color: #000066;">=</span> <span style="color: #0000ff;">10000000</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">type</span>
  TVariableRec <span style="color: #000066;">=</span> <span style="color: #000000; font-weight: bold;">record</span>
  <span style="color: #000000; font-weight: bold;">private</span>
    FFLoat<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">;</span>
    FString<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
    FInteger<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">function</span> GetAsFloat<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">procedure</span> SetAsFloat<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">function</span> GetAsInteger<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">procedure</span> SetAsInteger<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">function</span> GetAsString<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">procedure</span> SetAsString<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">public</span>
    <span style="color: #000000; font-weight: bold;">class</span> operator Implicit<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">:</span> TVariableRec<span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">class</span> operator Implicit<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">:</span> TVariableRec<span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">class</span> operator Implicit<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">:</span> TVariableRec<span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">class</span> operator Implicit<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> TVariableRec<span style="color: #000066;">&#41;</span><span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">class</span> operator Implicit<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> TVariableRec<span style="color: #000066;">&#41;</span><span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">class</span> operator Implicit<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> TVariableRec<span style="color: #000066;">&#41;</span><span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">property</span> AsFloat<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span> <span style="color: #000066;">read</span> GetAsFloat <span style="color: #000066;">write</span> SetAsFloat<span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">property</span> AsString<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span> <span style="color: #000066;">read</span> GetAsString <span style="color: #000066;">write</span> SetAsString<span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">property</span> AsInteger<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span> <span style="color: #000066;">read</span> GetAsInteger <span style="color: #000066;">write</span> SetAsInteger<span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> tryTValue<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">var</span>
  i<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">integer</span><span style="color: #000066;">;</span>
  j<span style="color: #000066;">:</span> TValue<span style="color: #000066;">;</span>
  value1<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
  value2<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">;</span>
  value3<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  <span style="color: #000000; font-weight: bold;">for</span> I <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">1</span> <span style="color: #000000; font-weight: bold;">to</span> HUNDRED_MILLION <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">begin</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> I<span style="color: #000066;">;</span>
    value1 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">.</span><span style="color: #006600;">AsInteger</span><span style="color: #000066;">;</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> I <span style="color: #000066;">/</span> <span style="color: #0000ff;">5</span><span style="color: #000066;">;</span>
    value2 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">.</span><span style="color: #006600;">AsExtended</span><span style="color: #000066;">;</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">IntToStr</span><span style="color: #000066;">&#40;</span>I<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    value3 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">.</span><span style="color: #006600;">AsString</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value1<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value2<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value3<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> tryAnyValue<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">var</span>
  i<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">integer</span><span style="color: #000066;">;</span>
  j<span style="color: #000066;">:</span> TAnyValue<span style="color: #000066;">;</span>
  value1<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
  value2<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">;</span>
  value3<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  <span style="color: #000000; font-weight: bold;">for</span> I <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">1</span> <span style="color: #000000; font-weight: bold;">to</span> HUNDRED_MILLION <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">begin</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> I<span style="color: #000066;">;</span>
    value1 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">.</span><span style="color: #006600;">AsInteger</span><span style="color: #000066;">;</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> I <span style="color: #000066;">/</span> <span style="color: #0000ff;">5</span><span style="color: #000066;">;</span>
    value2 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">.</span><span style="color: #006600;">AsFloat</span><span style="color: #000066;">;</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">IntToStr</span><span style="color: #000066;">&#40;</span>I<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    value3 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">.</span><span style="color: #006600;">AsString</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value1<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value2<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value3<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> tryOmniValue<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">var</span>
  i<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">integer</span><span style="color: #000066;">;</span>
  j<span style="color: #000066;">:</span> TOmniValue<span style="color: #000066;">;</span>
  value1<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
  value2<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">;</span>
  value3<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  <span style="color: #000000; font-weight: bold;">for</span> I <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">1</span> <span style="color: #000000; font-weight: bold;">to</span> HUNDRED_MILLION <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">begin</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> I<span style="color: #000066;">;</span>
    value1 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">.</span><span style="color: #006600;">AsInteger</span><span style="color: #000066;">;</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> I <span style="color: #000066;">/</span> <span style="color: #0000ff;">5</span><span style="color: #000066;">;</span>
    value2 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">.</span><span style="color: #006600;">AsExtended</span><span style="color: #000066;">;</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">IntToStr</span><span style="color: #000066;">&#40;</span>I<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    value3 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">.</span><span style="color: #006600;">AsString</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value1<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value2<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value3<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> tryVariants<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">var</span>
  i<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">integer</span><span style="color: #000066;">;</span>
  j<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">variant</span><span style="color: #000066;">;</span>
  value1<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
  value2<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">;</span>
  value3<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  <span style="color: #000000; font-weight: bold;">for</span> I <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">1</span> <span style="color: #000000; font-weight: bold;">to</span> HUNDRED_MILLION <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">begin</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> I<span style="color: #000066;">;</span>
    value1 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">;</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> I <span style="color: #000066;">/</span> <span style="color: #0000ff;">5</span><span style="color: #000066;">;</span>
    value2 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">;</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">IntToStr</span><span style="color: #000066;">&#40;</span>I<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    value3 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value1<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value2<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value3<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> tryVarRec<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">var</span>
  i<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">integer</span><span style="color: #000066;">;</span>
  j<span style="color: #000066;">:</span> TVariableRec<span style="color: #000066;">;</span>
  value1<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
  value2<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">;</span>
  value3<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  <span style="color: #000000; font-weight: bold;">for</span> I <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">1</span> <span style="color: #000000; font-weight: bold;">to</span> HUNDRED_MILLION <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">begin</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> I<span style="color: #000066;">;</span>
    value1 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">.</span><span style="color: #006600;">AsInteger</span><span style="color: #000066;">;</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> I <span style="color: #000066;">/</span> <span style="color: #0000ff;">5</span><span style="color: #000066;">;</span>
    value2 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">.</span><span style="color: #006600;">AsFloat</span><span style="color: #000066;">;</span>
    j <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">IntToStr</span><span style="color: #000066;">&#40;</span>I<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    value3 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> j<span style="color: #000066;">.</span><span style="color: #006600;">AsString</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value1<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value2<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>value3<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span>
  stopwatch<span style="color: #000066;">:</span> TStopWatch<span style="color: #000066;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">{ TVariableRec }</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> operator TVariableRec<span style="color: #000066;">.</span><span style="color: #006600;">Implicit</span><span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">:</span> TVariableRec<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  Result<span style="color: #000066;">.</span><span style="color: #006600;">AsFloat</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> Value<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> TVariableRec<span style="color: #000066;">.</span><span style="color: #006600;">GetAsFloat</span><span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  Result <span style="color: #000066;">:</span><span style="color: #000066;">=</span> FFLoat<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> TVariableRec<span style="color: #000066;">.</span><span style="color: #006600;">GetAsInteger</span><span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  Result <span style="color: #000066;">:</span><span style="color: #000066;">=</span> FInteger<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> TVariableRec<span style="color: #000066;">.</span><span style="color: #006600;">GetAsString</span><span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  Result <span style="color: #000066;">:</span><span style="color: #000066;">=</span> FString<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> operator TVariableRec<span style="color: #000066;">.</span><span style="color: #006600;">Implicit</span><span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">:</span> TVariableRec<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  Result<span style="color: #000066;">.</span><span style="color: #006600;">AsInteger</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> Value<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> operator TVariableRec<span style="color: #000066;">.</span><span style="color: #006600;">Implicit</span><span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> TVariableRec<span style="color: #000066;">&#41;</span><span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  Result <span style="color: #000066;">:</span><span style="color: #000066;">=</span> Value<span style="color: #000066;">.</span><span style="color: #006600;">AsInteger</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> operator TVariableRec<span style="color: #000066;">.</span><span style="color: #006600;">Implicit</span><span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> TVariableRec<span style="color: #000066;">&#41;</span><span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  Result <span style="color: #000066;">:</span><span style="color: #000066;">=</span> Value<span style="color: #000066;">.</span><span style="color: #006600;">AsFloat</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> operator TVariableRec<span style="color: #000066;">.</span><span style="color: #006600;">Implicit</span><span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">:</span> TVariableRec<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  Result<span style="color: #000066;">.</span><span style="color: #006600;">AsString</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> Value<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> operator TVariableRec<span style="color: #000066;">.</span><span style="color: #006600;">Implicit</span><span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> TVariableRec<span style="color: #000066;">&#41;</span><span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  Result <span style="color: #000066;">:</span><span style="color: #000066;">=</span> Value<span style="color: #000066;">.</span><span style="color: #006600;">AsString</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> TVariableRec<span style="color: #000066;">.</span><span style="color: #006600;">SetAsFloat</span><span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Extended</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  FFLoat <span style="color: #000066;">:</span><span style="color: #000066;">=</span> Value<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> TVariableRec<span style="color: #000066;">.</span><span style="color: #006600;">SetAsInteger</span><span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  FInteger <span style="color: #000066;">:</span><span style="color: #000066;">=</span> Value<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">procedure</span> TVariableRec<span style="color: #000066;">.</span><span style="color: #006600;">SetAsString</span><span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Value<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">string</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  FString <span style="color: #000066;">:</span><span style="color: #000066;">=</span> Value<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">begin</span>
  <span style="color: #000000; font-weight: bold;">try</span>
    stopwatch <span style="color: #000066;">:</span><span style="color: #000066;">=</span> TStopWatch<span style="color: #000066;">.</span><span style="color: #006600;">StartNew</span><span style="color: #000066;">;</span>
    tryVariants<span style="color: #000066;">;</span>
    stopwatch<span style="color: #000066;">.</span><span style="color: #006600;">Stop</span><span style="color: #000066;">;</span>
    <span style="color: #000066;">writeln</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Variants: '</span><span style="color: #000066;">,</span> stopwatch<span style="color: #000066;">.</span><span style="color: #006600;">ElapsedMilliseconds</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    stopwatch <span style="color: #000066;">:</span><span style="color: #000066;">=</span> TStopWatch<span style="color: #000066;">.</span><span style="color: #006600;">StartNew</span><span style="color: #000066;">;</span>
    tryTValue<span style="color: #000066;">;</span>
    stopwatch<span style="color: #000066;">.</span><span style="color: #006600;">Stop</span><span style="color: #000066;">;</span>
    <span style="color: #000066;">writeln</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'TValue: '</span><span style="color: #000066;">,</span> stopwatch<span style="color: #000066;">.</span><span style="color: #006600;">ElapsedMilliseconds</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    stopwatch <span style="color: #000066;">:</span><span style="color: #000066;">=</span> TStopWatch<span style="color: #000066;">.</span><span style="color: #006600;">StartNew</span><span style="color: #000066;">;</span>
    tryAnyValue<span style="color: #000066;">;</span>
    stopwatch<span style="color: #000066;">.</span><span style="color: #006600;">Stop</span><span style="color: #000066;">;</span>
    <span style="color: #000066;">writeln</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'TAnyValue: '</span><span style="color: #000066;">,</span> stopwatch<span style="color: #000066;">.</span><span style="color: #006600;">ElapsedMilliseconds</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    stopwatch <span style="color: #000066;">:</span><span style="color: #000066;">=</span> TStopWatch<span style="color: #000066;">.</span><span style="color: #006600;">StartNew</span><span style="color: #000066;">;</span>
    tryOmniValue<span style="color: #000066;">;</span>
    stopwatch<span style="color: #000066;">.</span><span style="color: #006600;">Stop</span><span style="color: #000066;">;</span>
    <span style="color: #000066;">writeln</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'TOmniValue: '</span><span style="color: #000066;">,</span> stopwatch<span style="color: #000066;">.</span><span style="color: #006600;">ElapsedMilliseconds</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    stopwatch <span style="color: #000066;">:</span><span style="color: #000066;">=</span> TStopWatch<span style="color: #000066;">.</span><span style="color: #006600;">StartNew</span><span style="color: #000066;">;</span>
    tryVarRec<span style="color: #000066;">;</span>
    stopwatch<span style="color: #000066;">.</span><span style="color: #006600;">Stop</span><span style="color: #000066;">;</span>
    <span style="color: #000066;">writeln</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'TVariableRec: '</span><span style="color: #000066;">,</span> stopwatch<span style="color: #000066;">.</span><span style="color: #006600;">ElapsedMilliseconds</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">except</span>
    <span style="color: #000000; font-weight: bold;">on</span> E<span style="color: #000066;">:</span> Exception <span style="color: #000000; font-weight: bold;">do</span>
      <span style="color: #000066;">Writeln</span><span style="color: #000066;">&#40;</span>E<span style="color: #000066;">.</span><span style="color: #006600;">ClassName</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">': '</span><span style="color: #000066;">,</span> E<span style="color: #000066;">.</span><span style="color: #006600;">Message</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
&nbsp;
  <span style="color: #000066;">readln</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">.</span></pre></div></div>

<p style="text-align: justify;">It is obvious and expected that bare-bone record is the fastest. But Variants are not far behind and in real world the difference is negligible. My TAnyValue and TOmniValue from Primož are on the same level. But in most cases his implementation is faster because I use an interface to store the data in a class (because of my other code that uses interface based IAnyValue) and he stores most of the data as numeric type (only some as interface based class). I could speed up my implementation but I find it fast enough in most cases. And I will take elegance over speed if the difference is small enough. But TValue is slow, to slow probably to be used a lot. They should work on it in the future. It is a shame to throw it away since it brings quite a lot of power with it. I wonder if it is necessary for internal data to be stored as generics array</p>
<p style="text-align: justify;">For those of you who don&#8217;t like to use variants or want so more flexibility you can look for TAnyValue (which was inspired upon looking at TOmniValue implementation) or TOmniValue. They both work under older version of Delphi as far as I know (Delphi 2005 and up).</p>
<p style="text-align: justify;">If I missed something or if you know of another &#8220;variant&#8221; like implementation, please let me know. The purpose of this post is to explore this area as well as possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cromis.net/blog/2010/03/tvalue-and-other-variable-like-implementation-tests/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Build your XML the LinqToXML style in native code &#8211; Part I.</title>
		<link>http://www.cromis.net/blog/2010/03/build-your-xml-the-linqtoxml-style-in-native-code-part-i/</link>
		<comments>http://www.cromis.net/blog/2010/03/build-your-xml-the-linqtoxml-style-in-native-code-part-i/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 09:12:19 +0000</pubDate>
		<dc:creator>Iztok Kacin</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.cromis.net/blog/?p=698</guid>
		<description><![CDATA[A lot of you probably already know SimpleStorage. For those who don&#8217;t: http://www.cromis.net/blog/2008/07/simple-xml-based-storage/ http://www.cromis.net/blog/2008/07/simple-xml-based-storage-part-ii/ http://www.cromis.net/blog/2009/07/simple-xml-based-storage-part-iii/ http://www.cromis.net/blog/2010/02/what-is-new-in-simplestorage/ I read a blog entry recently about LinqToXML and while I was exploring the possibilities that it has, I wondered. Can something like this be done with Delphi and native code? Now SimpleStorage already enables you to write XML [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of you probably already know SimpleStorage. For those who don&#8217;t:</p>
<ul>
<li><a title="http://www.cromis.net/blog/2008/07/simple-xml-based-storage/" href="http://www.cromis.net/blog/2008/07/simple-xml-based-storage/">http://www.cromis.net/blog/2008/07/simple-xml-based-storage/</a></li>
<li><a title="http://www.cromis.net/blog/2008/07/simple-xml-based-storage-part-ii/" href="http://www.cromis.net/blog/2008/07/simple-xml-based-storage-part-ii/">http://www.cromis.net/blog/2008/07/simple-xml-based-storage-part-ii/</a></li>
<li><a title="http://www.cromis.net/blog/2009/07/simple-xml-based-storage-part-iii/" href="http://www.cromis.net/blog/2009/07/simple-xml-based-storage-part-iii/">http://www.cromis.net/blog/2009/07/simple-xml-based-storage-part-iii/</a></li>
<li><a title="http://www.cromis.net/blog/2010/02/what-is-new-in-simplestorage/" href="http://www.cromis.net/blog/2010/02/what-is-new-in-simplestorage/">http://www.cromis.net/blog/2010/02/what-is-new-in-simplestorage/</a></li>
</ul>
<p style="text-align: justify;">I read a blog entry recently about <a title="LinqToXML" href="http://www.delphifeeds.com/go/s/66053">LinqToXML</a> and while I was exploring the possibilities that it has, I wondered. Can something like this be done with Delphi and native code? Now SimpleStorage already enables you to write XML in a very compact and efficient way, but it still lacks some elegance on the more native XML building approach. Ok there is a question why would you even want to write XML code inside the IDE editor? But sometimes it is viable, maybe just a wrapper XML shell for something that gets dynamically injected into it. Nevertheless I was intrigued if it can be done. Primož Gabrijelčič  has done it and blogged about it:</p>
<ul>
<li><a title="http://17slon.com/blogs/gabr/2009/04/fluent-xml-1.html" href="http://17slon.com/blogs/gabr/2009/04/fluent-xml-1.html">http://17slon.com/blogs/gabr/2009/04/fluent-xml-1.html</a></li>
<li><a title="http://17slon.com/blogs/gabr/2009/04/fluent-xml-2.html" href="http://17slon.com/blogs/gabr/2009/04/fluent-xml-2.html">http://17slon.com/blogs/gabr/2009/04/fluent-xml-2.html</a></li>
</ul>
<p style="text-align: justify;">It was a nice display what fluent interfaces approach can do, but I was not happy completely. I was aiming at code that would get rid of the &#8220;Here, Back&#8230;&#8221; functions to navigate in the document, because you don&#8217;t need them. You always build your document in one swoop and maybe access single elements latter. I know why they were used in that approach and that is why I think with fluent interfaces alone it is hard to achieve the wanted result. SimpleStorage uses an approach similar to that, but not to full extent. The second reason was I wanted to implement it using SimpleStorage, because my aim is to evolve it to be a great and all around tool for XML and data manipulation.</p>
<p style="text-align: justify;">The goal I wanted to achieve was that the Delphi code written inside IDE would match the actual XML as closely as possible and with as little boilerplate code as possible. This way you get the benefit of seeing the resulting XML before it is even created. Without further delay let me show you the results.</p>
<p>First the XML we are trying to construct.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Demografija<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Males<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Janez<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Novak<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Janez<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Darko<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Gazvoda<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Darko<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Mitja<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Dežela<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Mitja<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Tilen<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Medved<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Tilen<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Males<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Females<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Person</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Marija&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Gorenjska<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Person</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Tanja&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Notranjska<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Person</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Maja&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Primorska<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Person</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Tadeja&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Pomurje<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Person</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Irma&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Posočje<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Person</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Marija&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Notranjska<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Females<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Demografija<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>And now the code that does it</p>

<div class="wp_syntax"><div class="code"><pre class="delphi" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">procedure</span> TfMain<span style="color: #000066;">.</span><span style="color: #006600;">btnExample2Click</span><span style="color: #000066;">&#40;</span>Sender<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">TObject</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">var</span>
  MyStorage<span style="color: #000066;">:</span> ISimpleStorage<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  MyStorage <span style="color: #000066;">:</span><span style="color: #000066;">=</span> CreateStorage<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Demografija'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
&nbsp;
  CreateBuilder<span style="color: #000066;">&#40;</span>MyStorage<span style="color: #000066;">&#41;</span><span style="color: #000066;">.</span><span style="color: #006600;">Construct</span><span style="color: #000066;">&#40;</span>
  <span style="color: #000066;">&#91;</span>
    AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Males'</span><span style="color: #000066;">,</span>
    <span style="color: #000066;">&#91;</span>
      AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Janez'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Novak'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
      AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Darko'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Gazvoda'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
      AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Mitja'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Dežela'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
      AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Tilen'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Medved'</span><span style="color: #000066;">&#41;</span>
    <span style="color: #000066;">&#93;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
    AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Females'</span><span style="color: #000066;">,</span>
    <span style="color: #000066;">&#91;</span>
      AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Person'</span><span style="color: #000066;">,</span> <span style="color: #000066;">&#91;</span><span style="color: #ff0000;">'Name'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Marija'</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Gorenjska'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
      AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Person'</span><span style="color: #000066;">,</span> <span style="color: #000066;">&#91;</span><span style="color: #ff0000;">'Name'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Tanja'</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Notranjska'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
      AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Person'</span><span style="color: #000066;">,</span> <span style="color: #000066;">&#91;</span><span style="color: #ff0000;">'Name'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Maja'</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Primorska'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
      AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Person'</span><span style="color: #000066;">,</span> <span style="color: #000066;">&#91;</span><span style="color: #ff0000;">'Name'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Tadeja'</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Pomurje'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
      AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Person'</span><span style="color: #000066;">,</span> <span style="color: #000066;">&#91;</span><span style="color: #ff0000;">'Name'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Irma'</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Posočje'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
      AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Person'</span><span style="color: #000066;">,</span> <span style="color: #000066;">&#91;</span><span style="color: #ff0000;">'Name'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Marija'</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Notranjska'</span><span style="color: #000066;">&#41;</span>
    <span style="color: #000066;">&#93;</span><span style="color: #000066;">&#41;</span>
  <span style="color: #000066;">&#93;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span></pre></div></div>

<p>And for the second example let me show how to inject the actual dynamically generated XML into the given builder template. The target XML is like this</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Books<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;English<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Science<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Mathematics</span> <span style="color: #000066;">Difficulty</span>=<span style="color: #ff0000;">&quot;High&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Mathematics<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Physics</span> <span style="color: #000066;">Difficulty</span>=<span style="color: #ff0000;">&quot;Low&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Physics<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Computers</span> <span style="color: #000066;">Difficulty</span>=<span style="color: #ff0000;">&quot;Medium&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>8<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Computers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Engineering</span> <span style="color: #000066;">Difficulty</span>=<span style="color: #ff0000;">&quot;Low&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Engineering<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Electoronics</span> <span style="color: #000066;">Difficulty</span>=<span style="color: #ff0000;">&quot;High&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>8<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Electoronics<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Biology<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Microbiology</span> <span style="color: #000066;">Difficulty</span>=<span style="color: #ff0000;">&quot;High&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Microbiology<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Undefined</span> <span style="color: #000066;">Difficulty</span>=<span style="color: #ff0000;">&quot;Low&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Undefined<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Biology<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Science<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Musical<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Classic<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Classic<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Etno<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Etno<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Pop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>8<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Pop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Musical<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/English<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Books<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>And the code that does it looks like this</p>

<div class="wp_syntax"><div class="code"><pre class="delphi" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">procedure</span> TfMain<span style="color: #000066;">.</span><span style="color: #006600;">btnExample1Click</span><span style="color: #000066;">&#40;</span>Sender<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">TObject</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">var</span>
  MyStorage<span style="color: #000066;">:</span> ISimpleStorage<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  MyStorage <span style="color: #000066;">:</span><span style="color: #000066;">=</span> CreateStorage<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Books'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
&nbsp;
  CreateBuilder<span style="color: #000066;">&#40;</span>MyStorage<span style="color: #000066;">&#41;</span><span style="color: #000066;">.</span><span style="color: #006600;">Construct</span><span style="color: #000066;">&#40;</span>
  <span style="color: #000066;">&#91;</span>
    AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'English'</span><span style="color: #000066;">,</span>
    <span style="color: #000066;">&#91;</span>
      AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Science'</span><span style="color: #000066;">,</span>
      <span style="color: #000066;">&#91;</span>
        AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Mathematics'</span><span style="color: #000066;">,</span> <span style="color: #000066;">&#91;</span><span style="color: #ff0000;">'Difficulty'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'High'</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">5</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
        AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Physics'</span><span style="color: #000066;">,</span> <span style="color: #000066;">&#91;</span><span style="color: #ff0000;">'Difficulty'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Low'</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">0</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
        AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Computers'</span><span style="color: #000066;">,</span> <span style="color: #000066;">&#91;</span><span style="color: #ff0000;">'Difficulty'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Medium'</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">8</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
        AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Engineering'</span><span style="color: #000066;">,</span> <span style="color: #000066;">&#91;</span><span style="color: #ff0000;">'Difficulty'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Low'</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">4</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
        AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Electoronics'</span><span style="color: #000066;">,</span> <span style="color: #000066;">&#91;</span><span style="color: #ff0000;">'Difficulty'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'High'</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">8</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
        AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Biology'</span><span style="color: #000066;">,</span>
        <span style="color: #000066;">&#91;</span>
          AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Microbiology'</span><span style="color: #000066;">,</span> <span style="color: #000066;">&#91;</span><span style="color: #ff0000;">'Difficulty'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'High'</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">4</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
          AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Undefined'</span><span style="color: #000066;">,</span> <span style="color: #000066;">&#91;</span><span style="color: #ff0000;">'Difficulty'</span><span style="color: #000066;">,</span> <span style="color: #ff0000;">'Low'</span><span style="color: #000066;">&#93;</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">3</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
          Add<span style="color: #000066;">&#40;</span>
            <span style="color: #000000; font-weight: bold;">procedure</span><span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Element<span style="color: #000066;">:</span> IElement<span style="color: #000066;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">begin</span>
              <span style="color: #808080; font-style: italic;">// add few elements here</span>
              Element<span style="color: #000066;">.</span><span style="color: #000066;">Append</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'InsertedNode'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">.</span><span style="color: #006600;">AsInteger</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">1</span><span style="color: #000066;">;</span>
              Element<span style="color: #000066;">.</span><span style="color: #000066;">Append</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'InsertedNode'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">.</span><span style="color: #006600;">AsInteger</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">2</span><span style="color: #000066;">;</span>
              Element<span style="color: #000066;">.</span><span style="color: #000066;">Append</span><span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'InsertedNode'</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">.</span><span style="color: #006600;">AsInteger</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #0000ff;">3</span><span style="color: #000066;">;</span>
            <span style="color: #000000; font-weight: bold;">end</span>
          <span style="color: #000066;">&#41;</span>
        <span style="color: #000066;">&#93;</span><span style="color: #000066;">&#41;</span>
      <span style="color: #000066;">&#93;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
      AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Musical'</span><span style="color: #000066;">,</span>
      <span style="color: #000066;">&#91;</span>
        AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Classic'</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">2</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
        AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Etno'</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">2</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span>
        AddElement<span style="color: #000066;">&#40;</span><span style="color: #ff0000;">'Pop'</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">8</span><span style="color: #000066;">&#41;</span>
      <span style="color: #000066;">&#93;</span><span style="color: #000066;">&#41;</span>
    <span style="color: #000066;">&#93;</span><span style="color: #000066;">&#41;</span>
  <span style="color: #000066;">&#93;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span></pre></div></div>

<p style="text-align: justify;">The result is easily readable dont&#8217; you think? I would really like to hear your opinion on the code. Maybe you have a suggestion or idea, or you simply have a comment about how it all sucks <img src='http://www.cromis.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  The code can already be downloaded from my download page, but be warned, it is still in early development and it will change. It only works in Delphi 2010 (should in 2009) opposed to other parts of SimpleStorage that work in Delphi 2006 and up. Also I use Variants for values for now and that will change. I will replace them with records and implicit operator overloads.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cromis.net/blog/2010/03/build-your-xml-the-linqtoxml-style-in-native-code-part-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
