<?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>A little bit of zis, a little byte of zat &#187; Delphi</title>
	<atom:link href="http://fgaillard.com/category/delphi/feed/" rel="self" type="application/rss+xml" />
	<link>http://fgaillard.com</link>
	<description>François on Delphi Programming, Programming in general and the rest...</description>
	<lastBuildDate>Fri, 16 Sep 2011 08:19:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>A little bit of zis, etc. #3</title>
		<link>http://fgaillard.com/2011/09/a-little-bit-of-zis-etc-3/</link>
		<comments>http://fgaillard.com/2011/09/a-little-bit-of-zis-etc-3/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 08:19:36 +0000</pubDate>
		<dc:creator>François Gaillard</dc:creator>
				<category><![CDATA[Conference]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Jobs]]></category>

		<guid isPermaLink="false">http://fgaillard.com/?p=415</guid>
		<description><![CDATA[Back from the DelphiLive conference&#8230; A big thank you to Frank and Michael who made this a very nice event. There was a lot of excitement about the new XE2, from the attendees to the speakers to the Delphi team. &#8230; <a href="http://fgaillard.com/2011/09/a-little-bit-of-zis-etc-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Back from the DelphiLive conference&#8230;</p>
<ul>
<li>A big thank you to Frank and Michael who made this a very nice event.</li>
<li>There was a lot of excitement about the new XE2, from the attendees to the speakers to the Delphi team.</li>
<li>The crowd was not huge, but there was a lot of energy and good vibes.</li>
<li>Mason Wheeler has <a href="http://tech.turbu-rpg.com/365/delphilive-keynote-overview">a very good report of the Keynote</a> on his <a href="http://tech.turbu-rpg.com/">blog</a>.</li>
<li>My thanks to those who attended my sessions. I will clean a bit my material and have it available online&#8230; But not before next week.</li>
<li><a href="http://www.simonjstuart.com/">Simon Stuart</a> ( of TKinect et al. fame) was not at the conference in San Jose, but I bet he&#8217;ll have very interesting sessions at the coming online CodeRage.</li>
<li>You can help him help the Delphi community <a href="http://www.simonjstuart.com/2011/09/12/lua4delphi-fundraiser/"><strong>here </strong></a>.</li>
<li>Interestingly, <a href="http://www.nickhodges.com/">Nick Hodges</a> was there not only as a speaker, but also to recruit for his company <a href="http://www.nickhodges.com/post/Gateway-Ticketing-Needs-Developers.aspx">Gateway Ticketing</a>.</li>
<li>And he was in competition with my former company <a href="http://www.wideorbit.com/">WideOrbit </a>who were there sponsoring the &#8220;Meet the Team&#8221; event and getting contacts and resumes to fill a <a href="http://www.wideorbit.com/careers/index.php/jobs">lot of jobs openings</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://fgaillard.com/2011/09/a-little-bit-of-zis-etc-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A little bit of zis, etc. #2</title>
		<link>http://fgaillard.com/2011/08/a-little-bit-of-zis-etc-2/</link>
		<comments>http://fgaillard.com/2011/08/a-little-bit-of-zis-etc-2/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 07:11:14 +0000</pubDate>
		<dc:creator>François Gaillard</dc:creator>
				<category><![CDATA[Conference]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Motorcycle]]></category>
		<category><![CDATA[TIOBE]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://fgaillard.com/?p=407</guid>
		<description><![CDATA[I know, I&#8217;ve been not very much of a blogger lately&#8230; Delphi XE2 is announced and it surely looks like a very interesting release (and probably with some nasty bugs as well, we&#8217;ll see)&#8230; I take the bet it will &#8230; <a href="http://fgaillard.com/2011/08/a-little-bit-of-zis-etc-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I know, I&#8217;ve been not very much of a blogger lately&#8230;</p>
<ul>
<li><a href="http://www.andreanolanusse.com/en/rad-studio-xe2-a-new-era-for-delphi-and-cbuilder-developers/">Delphi XE2 is announced</a> and it surely looks like a very interesting release (and probably with some nasty bugs as well, we&#8217;ll see)&#8230;</li>
<li>I take the bet it will up Delphi a bit in the <a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html">TIOBE index</a> if it creates the buzz I think it will.</li>
<li>I will speak at the <a href="http://delphilive.com/">DelphiLive 2011</a> in San Jose, which I hope will be a good edition with a lot of XE2 goodies&#8230;.</li>
<li><a href="http://www.thewildernessdowntown.com/#37.802018,-122.41963">Something really cool made with HTML5</a> (better try it with Chrome).<br />
You&#8217;ll arrive at the top of Lombard street in SF, but when it&#8217;s finished you can try with any point having a street view in Google maps.</li>
<li>Internet is good because it keeps a trace of a lot of code snippets.<br />
Internet is bad because it keeps a trace of a lot of code snippets. <img src='http://fgaillard.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /><br />
My next post should explain&#8230;</li>
<li>We have implemented some panning and zooming features in our Adura System Design application: it&#8217;s still cool what you can do with plain old Winapi and Delphi.<br />
I guess it would be totally sick with FireMonkey (if we do it, but it&#8217;s probably a huge rewrite).</li>
<li>The <a href="http://www.siliconvalley-codecamp.com/">Silicon Valley Code Camp</a> is back! Saturday and Sunday, October 8th and 9th, 2011. As I said in a <a href="http://fgaillard.com/2010/10/codecamp-2010-awesome/">previous post</a>, it&#8217;s not very Delphi but totally cool.</li>
<li>Lately I&#8217;ve been back into motorcycling (thanks to my lovely and adventurous wife) and I got my first cruiser ever.<br />
Absolutely gorgeous design but bad UI nevertheless: The control panel is not on the handlebar but on top of the tank with the turn signals indicators at the very bottom, which means you cannot just see them if you have a full face helmet, they are hidden by the chin bar and you have to bow your head and freakin&#8217; look at them.<br />
And because those turn signals do not go off automatically, I ride quite often with them on for a while and that p..sses me off.<br />
<a href="http://fgaillard.com/wp-content/uploads/2011/08/gauge_view2.jpg"><img class="alignnone size-medium wp-image-411" title="gauge_view2" src="http://fgaillard.com/wp-content/uploads/2011/08/gauge_view2-300x200.jpg" alt="" width="300" height="200" /></a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://fgaillard.com/2011/08/a-little-bit-of-zis-etc-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Unfortunate Effect of WM_SETREDRAW</title>
		<link>http://fgaillard.com/2011/02/the-unfortunate-effect-of-wm_setredraw/</link>
		<comments>http://fgaillard.com/2011/02/the-unfortunate-effect-of-wm_setredraw/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 02:59:34 +0000</pubDate>
		<dc:creator>François Gaillard</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[LockWindowUpdate]]></category>

		<guid isPermaLink="false">http://fgaillard.com/?p=382</guid>
		<description><![CDATA[&#8230; or why simply replacing LockWindowUpdate by WM_SETREDRAW is not that straightforward. As you know, when you want to avoid flickering or multiple partial redraws of your Forms, during a flurry of updates for instance, even though it is very &#8230; <a href="http://fgaillard.com/2011/02/the-unfortunate-effect-of-wm_setredraw/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>&#8230; or why simply replacing <em>LockWindowUpdate</em> by <em>WM_SETREDRAW</em> is not that straightforward.</h3>
<p>As you know, when you want to avoid flickering or multiple partial redraws of your Forms, during a flurry of updates for instance,  even though it is very tempting, <strong>you must not use <em>LockWindowUpdate</em></strong>. The Windows documentation has been updated from the days when it practically enticed people into using this API call for this wrong purpose and Raymond Chen has explained in detail why:<br />
<a href="http://blogs.msdn.com/b/oldnewthing/archive/2007/02/19/1716211.aspx">What does LockWindowUpdate do?</a><br />
<a href="http://blogs.msdn.com/b/oldnewthing/archive/2007/02/21/1735472.aspx">With what operations is LockWindowUpdate meant to be used?</a><br />
<a href="http://blogs.msdn.com/b/oldnewthing/archive/2007/02/22/1742084.aspx#1745732">With what operations is LockWindowUpdate not meant to be used?</a><br />
<a href="http://blogs.msdn.com/b/oldnewthing/archive/2007/02/23/1747713.aspx">Final remarks on LockWindowUpdate</a></p>
<p>Now, just replacing <code><font size="+1">LockWindowUpdate(MyForm.Handle)</font></code> by <code><font size="+1">SendMessage(MyForm.Handle, WM_SETREDRAW, 0, 0)</font></code> on the whole Form <strong>is not the solution either</strong>. <span id="more-382"></span>Even though I&#8217;ve seen it recommended here or there.<br />
Oh, it does a good job at preventing any painting on the Form, and if drawing is re-enabled quickly enough, there is little chance to cause the problem we&#8217;ll see below.</p>
<h3>Simulate a long calculation that coincides with some visible UI changes.</h3>
<p>Create a new VCL Forms application and put 2 Buttons on the Main Form.<br />
In the 1st ButtonClick handler, paste the following code:</p>
<pre><code><span style="font: 10pt Courier New;"><span class="pas1-reservedword">procedure</span><span class="pas1-space"> TForm1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Button1Click</span><span class="pas1-symbol">(</span><span class="pas1-identifier">Sender</span><span class="pas1-symbol">:</span><span class="pas1-space"> TObject</span><span class="pas1-symbol">);
</span><span class="pas1-reservedword">begin
</span><span class="pas1-space">  Button1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Width </span><span class="pas1-symbol">:=</span><span class="pas1-space"> Button1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Width</span><span class="pas1-symbol">*</span><span class="pas1-number">2</span><span class="pas1-symbol">;
</span><span class="pas1-space">  Repaint</span><span class="pas1-symbol">;
</span><span class="pas1-space">  sleep</span><span class="pas1-symbol">(</span><span class="pas1-number">2000</span><span class="pas1-symbol">);
</span><span class="pas1-space">  Button1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Width </span><span class="pas1-symbol">:=</span><span class="pas1-space"> Button1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Width </span><span class="pas1-reservedword">div</span><span class="pas1-space"> </span><span class="pas1-number">2</span><span class="pas1-symbol">;
</span><span class="pas1-space">  Repaint</span><span class="pas1-symbol">;
</span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;
</span></span></code></pre>
<p>If you click the button, its size changes, the application stays unresponsive for 2 s (lengthy processing without a background thread) then everything is back to normal. If you click on the Form while it is &#8220;frozen&#8221; nothing happens unless you have an onClick event, or try to move the Form for instance, and in that case the event action is executed after the Form is unfrozen, when message processing can resume and handle the backlog.</p>
<h3>Now, if you don&#8217;t want the UI changes to be visible.</h3>
<p>You can wrap all that code with WM_SETREDRAW (like you&#8217;d be tempted to do with LockWindoUpdate):</p>
<pre><code><span style="font: 10pt Courier New;"><span class="pas1-reservedword">procedure</span><span class="pas1-space"> TForm1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Button1Click</span><span class="pas1-symbol">(</span><span class="pas1-identifier">Sender</span><span class="pas1-symbol">:</span><span class="pas1-space"> TObject</span><span class="pas1-symbol">);
</span><span class="pas1-reservedword">begin
</span><span class="pas1-space">  SendMessage</span><span class="pas1-symbol">(</span><span class="pas1-identifier">Handle</span><span class="pas1-symbol">,</span><span class="pas1-space"> WM_SETREDRAW</span><span class="pas1-symbol">,</span><span class="pas1-space"> Ord</span><span class="pas1-symbol">(</span><span class="pas1-identifier">False</span><span class="pas1-symbol">),</span><span class="pas1-space"> </span><span class="pas1-number">0</span><span class="pas1-symbol">);
</span><span class="pas1-space">  </span><span class="pas1-reservedword">try
</span><span class="pas1-space">    Button1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Width </span><span class="pas1-symbol">:=</span><span class="pas1-space"> Button1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Width</span><span class="pas1-symbol">*</span><span class="pas1-number">2</span><span class="pas1-symbol">;
</span><span class="pas1-space">    Repaint</span><span class="pas1-symbol">;
</span><span class="pas1-space">    sleep</span><span class="pas1-symbol">(</span><span class="pas1-number">2000</span><span class="pas1-symbol">);
</span><span class="pas1-space">    Button1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Width </span><span class="pas1-symbol">:=</span><span class="pas1-space"> Button1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Width </span><span class="pas1-reservedword">div</span><span class="pas1-space"> </span><span class="pas1-number">2</span><span class="pas1-symbol">;
</span><span class="pas1-space">    Repaint</span><span class="pas1-symbol">;
</span><span class="pas1-space">  </span><span class="pas1-reservedword">finally
</span><span class="pas1-space">    SendMessage</span><span class="pas1-symbol">(</span><span class="pas1-identifier">Handle</span><span class="pas1-symbol">,</span><span class="pas1-space"> WM_SETREDRAW</span><span class="pas1-symbol">,</span><span class="pas1-space"> Ord</span><span class="pas1-symbol">(</span><span class="pas1-identifier">True</span><span class="pas1-symbol">),</span><span class="pas1-space"> </span><span class="pas1-number">0</span><span class="pas1-symbol">);
</span><span class="pas1-space">  </span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;
</span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;</span></span></code></pre>
<p>Try it again. Seems good, the button size does not appear to change. But, wait!<br />
Try to click anywhere on the form while it is &#8220;busy&#8221;.<br />
<strong>Oops! Clicked through it, like it did not even exist!</strong><br />
It&#8217;s even more obvious when the form is above the Delphi editor: as soon as you click the button, the cursor changes from the regular Arrow pointer to the text IBeam.</p>
<h3>Try with Notepad.</h3>
<p>In case you&#8217;d believe it is some defect special to the VCL Forms, you can try and paste the following code in the 2nd Button OnClick handler. It opens Notepad for a new text document, prevents redrawing on it for 3s then re-enables it.<br />
<em>Note:</em> If the window title is different (non English Windows&#8230;), you may have to adapt the 2nd FindWindow parameter or use an empty string.</p>
<pre><code><span style="font: 10pt Courier New;"><span class="pas1-reservedword">procedure</span><span class="pas1-space"> TForm1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Button2Click</span><span class="pas1-symbol">(</span><span class="pas1-identifier">Sender</span><span class="pas1-symbol">:</span><span class="pas1-space"> TObject</span><span class="pas1-symbol">);
</span><span class="pas1-reservedword">var
</span><span class="pas1-space">  h</span><span class="pas1-symbol">:</span><span class="pas1-space"> THandle</span><span class="pas1-symbol">;
</span><span class="pas1-reservedword">begin
</span><span class="pas1-space">  ShellExecute</span><span class="pas1-symbol">(</span><span class="pas1-identifier">Handle</span><span class="pas1-symbol">,</span><span class="pas1-space"> </span><span class="pas1-reservedword">nil</span><span class="pas1-symbol">,</span><span class="pas1-space"> </span><span class="pas1-string">'Notepad.exe'</span><span class="pas1-symbol">,</span><span class="pas1-space"> </span><span class="pas1-string">''</span><span class="pas1-symbol">,</span><span class="pas1-string">''</span><span class="pas1-symbol">,</span><span class="pas1-space"> SW_SHOWNORMAL</span><span class="pas1-symbol">);
</span><span class="pas1-space">  sleep</span><span class="pas1-symbol">(</span><span class="pas1-number">100</span><span class="pas1-symbol">);
</span><span class="pas1-space">  </span><span class="pas1-comment">// you may have to change the default title in non English Win7 or put ''
</span><span class="pas1-space">  h </span><span class="pas1-symbol">:=</span><span class="pas1-space"> FindWindow</span><span class="pas1-symbol">(</span><span class="pas1-string">'Notepad'</span><span class="pas1-symbol">,</span><span class="pas1-space"> </span><span class="pas1-string">'Untitled - Notepad'</span><span class="pas1-symbol">);
</span><span class="pas1-space">  </span><span class="pas1-reservedword">if</span><span class="pas1-space"> IsWindow</span><span class="pas1-symbol">(</span><span class="pas1-identifier">h</span><span class="pas1-symbol">)</span><span class="pas1-space"> </span><span class="pas1-reservedword">then</span><span class="pas1-space"> </span><span class="pas1-reservedword">begin
</span><span class="pas1-space">    SendMessage</span><span class="pas1-symbol">(</span><span class="pas1-identifier">h</span><span class="pas1-symbol">,</span><span class="pas1-space"> WM_SETREDRAW</span><span class="pas1-symbol">,</span><span class="pas1-space"> Ord</span><span class="pas1-symbol">(</span><span class="pas1-identifier">False</span><span class="pas1-symbol">),</span><span class="pas1-space"> </span><span class="pas1-number">0</span><span class="pas1-symbol">);
</span><span class="pas1-space">    </span><span class="pas1-reservedword">try
</span><span class="pas1-space">      sleep</span><span class="pas1-symbol">(</span><span class="pas1-number">3000</span><span class="pas1-symbol">);
</span><span class="pas1-space">    </span><span class="pas1-reservedword">finally
</span><span class="pas1-space">      SendMessage</span><span class="pas1-symbol">(</span><span class="pas1-identifier">h</span><span class="pas1-symbol">,</span><span class="pas1-space"> WM_SETREDRAW</span><span class="pas1-symbol">,</span><span class="pas1-space"> Ord</span><span class="pas1-symbol">(</span><span class="pas1-identifier">True</span><span class="pas1-symbol">),</span><span class="pas1-space"> </span><span class="pas1-number">0</span><span class="pas1-symbol">);
</span><span class="pas1-space">    </span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;
</span><span class="pas1-space">  </span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;
</span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;</span></span></code></pre>
<p>Try to click anywhere on the Notepad window when it is &#8220;locked&#8221;, you&#8217;ll get right through it just as well!</p>
<h3>What if you need to prevent drawing on the Form while doing some processing?</h3>
<p>As it is very rare that the UI controls subject to unwanted drawing are directly placed on the Form, the easiest solution is to prevent drawing for the utmost parent, very often a Panel or a Tab/PageControl (the ClientWindow would not work).<br />
And if you don&#8217;t have a master parent, you can always insert a Panel with alClient as a main container between the Form and the rest of the controls.<br />
Useful tip: Contrary to <em>DisableControls/EnableControls</em> for the DataSets, <em>WM_SETREDRAW</em> does not care about nested calls, it does not matter how many times you call WM_SETREDRAW False (although avoiding sending unnecessary messages flying around is always desirable). You just have to guarantee that you&#8217;ll call WM_SETREDRAW True when you are done with your updates.</p>
<h3>Why do we have this strange behavior?</h3>
<p>Practically, <em>WM_SETREDRAW</em> default behavior is for the Window receiving it to disappear, but without causing the screen to be refreshed to show what&#8217;s behind. We are left with a &#8220;ghost&#8221; painting of the current Window, and is truly very static indeed.<br />
It has been explained, sort of,  by Raymond Chen in a very recent post:<br />
<a href="http://blogs.msdn.com/b/oldnewthing/archive/2011/01/24/10119211.aspx">There&#8217;s a default implementation for WM_SETREDRAW, but you might be able to do better</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fgaillard.com/2011/02/the-unfortunate-effect-of-wm_setredraw/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>When The Debugger Leaks&#8230;</title>
		<link>http://fgaillard.com/2011/02/when-the-debugger-leaks/</link>
		<comments>http://fgaillard.com/2011/02/when-the-debugger-leaks/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 21:19:33 +0000</pubDate>
		<dc:creator>François Gaillard</dc:creator>
				<category><![CDATA[Debugger]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Quality]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Memory Leaks]]></category>

		<guid isPermaLink="false">http://fgaillard.com/?p=375</guid>
		<description><![CDATA[&#8230; you may end up chasing memory leaks that don&#8217;t exist. I was at work investigating some bizarre behavior of our application when dealing with a big customer file and I had ReportMemoryLeaksOnShutdown turned on as it was very likely &#8230; <a href="http://fgaillard.com/2011/02/when-the-debugger-leaks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&#8230; you may end up chasing memory leaks that don&#8217;t exist.</p>
<p>I was at work investigating some bizarre behavior of our application when dealing with a big customer file and I had  <code>ReportMemoryLeaksOnShutdown</code> turned on as it was very likely there was some memory leaked.<br />
So, I donned my LeakBuster suit, armed my LeakBlaster and started hunting the leaks, <span id="more-375"></span>trying different workflows with different code-paths, putting some Breakpoints here or there with some Watches, and sure enough, I got a bunch of memory leaks reported upon closing the application. But those were somewhat bizarre, mainly UnicodeStrings with unhelpful stacktraces into the VCL like:<br />
<code>A memory block has been leaked. The size is: 36<br />
This block was allocated ... and the stack trace (return addresses) at the time was:<br />
4043E2 [System.pas][System][@GetMem][2979]<br />
20036<br />
The block is currently used for an object of class: Unknown</code><br />
or<br />
<code>A memory block has been leaked. The size is: 20<br />
This block was allocated ... and the stack trace (return addresses) at the time was:<br />
404972 [System.pas][System][System.@GetMem][3693]<br />
407B5B [System.pas][System][System.@NewUnicodeString][16751]<br />
407D8C [System.pas][System][System.@UStrFromPWCharLen][17431]<br />
...<br />
407E63 [System.pas][System][System.InternalUStrFromPCharLen][17601]<br />
The block is currently used for an object of class: UnicodeString</code></p>
<p>It took me some time to find a relatively simple workflow showing consistently a leak where I was pretty sure the code was OK and should not leak. Then I tried to run the application without debugging and it did not leak. And again within the debugger and it leaked again.<br />
So, the debugger was leaking memory. I don&#8217;t remember ever seeing that before, except in the cases where calling some buggy code from the Evaluate dialog or in the Watches was causing a leak.</p>
<p>You can try yourself in D2010 or XE with this very simple application: Create New VCL Form Application, double click in the Form designer to create a FormCreate handler and replace the empty procedure by this code:</p>
<pre><code><span style="font: 10pt Courier New;"><span class="pas1-reservedword">function</span><span class="pas1-space"> Test</span><span class="pas1-symbol">(</span><span class="pas1-identifier">s</span><span class="pas1-symbol">:</span><span class="pas1-space"> </span><span class="pas1-reservedword">string</span><span class="pas1-symbol">):</span><span class="pas1-space"> </span><span class="pas1-reservedword">string</span><span class="pas1-symbol">;
</span><span class="pas1-reservedword">begin
</span><span class="pas1-space">  Result </span><span class="pas1-symbol">:=</span><span class="pas1-space"> </span><span class="pas1-string">'test: '</span><span class="pas1-space"> </span><span class="pas1-symbol">+</span><span class="pas1-space"> s</span><span class="pas1-symbol">;
</span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;

</span><span class="pas1-reservedword">procedure</span><span class="pas1-space"> TForm1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">FormCreate</span><span class="pas1-symbol">(</span><span class="pas1-identifier">Sender</span><span class="pas1-symbol">:</span><span class="pas1-space"> TObject</span><span class="pas1-symbol">);
</span><span class="pas1-reservedword">begin
</span><span class="pas1-space">  ReportMemoryLeaksOnShutdown </span><span class="pas1-symbol">:=</span><span class="pas1-space"> True</span><span class="pas1-symbol">;
</span><span class="pas1-space">  ShowMessage</span><span class="pas1-symbol">(</span><span class="pas1-identifier">Test</span><span class="pas1-symbol">(</span><span class="pas1-string">'toto'</span><span class="pas1-symbol">));
</span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;
</span></span></code></pre>
<p>As you can see, this code cannot possibly leak. Run it and, as expected, it does not leak.<br />
Now put a break point on the ShowMessage line and create a watch to execute Test(&#8216;boo&#8217;), checking the &#8220;Allow side effects and function calls&#8221; in the watch dialog. Run the application, it stops before the ShowMessage and you can see the &#8216;test: boo&#8217; string value in the watch. Resume the execution, you get the ShowMessage and you can close the Application when the Main Form is shown.</p>
<p>Now, you get the dreaded Memory Leak Report dialog:<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Unexpected Memory Leak<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
An unexpected memory leak has occurred.<br />
The unexpected small block leaks are:85 &#8211; 92 bytes: UnicodeString x 1<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>The funny thing is that if you save this project &#8220;as is&#8221; and close Delphi, next time you restart Delphi and run it, it might not necessary leak even though you see the watch expression evaluated; you&#8217;d have to run it again or even open the watch dialog explictly and then boom! you&#8217;ll get the leak&#8230;.<br />
Anyway, as using &#8220;Evaluate&#8221; or &#8220;Watch&#8221; are common use cases when debugging, it&#8217;s very easy to find yourself with some strange memory leaks.</p>
<p>I have experienced this with D2010 and XE, with or without the full FastMM4. I don&#8217;t recall having this with D2007 or previous versions.</p>
<p>Do you Delphites out there see that behavior?<br />
(not yet logged in QC, but it looks very similar to <a href="http://qc.embarcadero.com/wc/qcmain.aspx?d=73762">QC# 73762</a>, so maybe that one just needs more visibility and more votes, and this new Use Case).</p>
]]></content:encoded>
			<wfw:commentRss>http://fgaillard.com/2011/02/when-the-debugger-leaks/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>A little bit of zis, etc.</title>
		<link>http://fgaillard.com/2010/12/a-little-bit-of-zis-etc/</link>
		<comments>http://fgaillard.com/2010/12/a-little-bit-of-zis-etc/#comments</comments>
		<pubDate>Fri, 24 Dec 2010 07:58:07 +0000</pubDate>
		<dc:creator>François Gaillard</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Quality]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[TIOBE]]></category>

		<guid isPermaLink="false">http://fgaillard.com/?p=370</guid>
		<description><![CDATA[I haven&#8217;t blogged in quite a while&#8230; I have been busy at work and at home. And now I&#8217;m with the family for an extended week-end in the mountains. So, this post will be more like a pot-pourri of little &#8230; <a href="http://fgaillard.com/2010/12/a-little-bit-of-zis-etc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t blogged in quite a while&#8230; I have been busy at work and at home. And now I&#8217;m with the family for an extended week-end in the mountains.</p>
<p>So, this post will be more like a pot-pourri of little tidbits a la <a href="http://www.nickhodges.com/post/Flotsam-and-Jetsam-17.aspx" target="_blank">Nick Hodges</a>.</p>
<ul>
<li><span style="font-size: 18px;">It&#8217;s kind of irritating when in Delphi&#8217;s editor the parenthesis matching goofs and counts those embedded in strings:</span></li>
<pre>Format<span style="color: #ff0000;"><strong><span style="color: #ff0000;">(</span></strong></span>'I have %d closing <span style="color: #ff0000;"><strong><span style="color: #ff0000;">)</span></strong></span>', [n])</pre>
<li><span style="font-size: 18px;">You don&#8217;t appreciate the comfort of doing software in a software realm, with pretty stable APIs, some sort of object model and a stuff called specifications, until you begin to deal with hardware devices that can make darwinism look like immobilism.</span></li>
<li><span style="font-size: 18px;">Delphi is back in the top 10 of the <a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html" target="_blank">TIOBE Index</a> this month. I guess it is a good sign. Don&#8217;t know if one can read too much in it&#8230;</span></li>
<li><span style="font-size: 18px;">Certainly, there is more to do to bump Delphi&#8217;s name recognition. My son is back home for the holidays from his college. He started this year in Software Engineering at a well known university. He has yet to hear about Delphi (except by myself at home).</span></li>
<li><span style="font-size: 18px;">It&#8217;s certainly time to wish you all very happy holidays. Enjoy time with you family and take care!</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://fgaillard.com/2010/12/a-little-bit-of-zis-etc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>French Delphi Speech Session Downloadable</title>
		<link>http://fgaillard.com/2010/11/french-delphi-speech-session-downloadable/</link>
		<comments>http://fgaillard.com/2010/11/french-delphi-speech-session-downloadable/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 07:16:58 +0000</pubDate>
		<dc:creator>François Gaillard</dc:creator>
				<category><![CDATA[Conference]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Speech]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[VCL]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[CodeWay]]></category>
		<category><![CDATA[ComCtrls]]></category>
		<category><![CDATA[RichEdit]]></category>

		<guid isPermaLink="false">http://fgaillard.com/?p=368</guid>
		<description><![CDATA[The zip of my CodeWay 4 session (in French) is now available for download here. FYI, the old CodeRage 4 session (in English) is also available from Embarcadero: &#8220;Speech Enabling Delphi Applications (zip)&#8221;]]></description>
			<content:encoded><![CDATA[<p>The zip of my CodeWay 4 session (in French) is now available for <a href="http://fgaillard.com/download/Speech_FR.zip">download here</a>.</p>
<p>FYI, the old CodeRage 4 session (in English) is also available from Embarcadero: <a rel="nofollow" href="http://cc.embarcadero.com/download.aspx?id=27264">&#8220;Speech Enabling Delphi Applications (zip)&#8221;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fgaillard.com/2010/11/french-delphi-speech-session-downloadable/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FieldByName, FindField: too convenient to be honest</title>
		<link>http://fgaillard.com/2010/11/fieldbyname-findfield-too-convenient-to-be-honest/</link>
		<comments>http://fgaillard.com/2010/11/fieldbyname-findfield-too-convenient-to-be-honest/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 01:08:13 +0000</pubDate>
		<dc:creator>François Gaillard</dc:creator>
				<category><![CDATA[Coding standard]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Quality]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[FieldByName]]></category>
		<category><![CDATA[Optimization]]></category>

		<guid isPermaLink="false">http://fgaillard.com/?p=365</guid>
		<description><![CDATA[I don&#8217;t know about you, but I can&#8217;t count anymore the number of times I&#8217;ve seen this code pattern (in code snippets online as well as in production code): while not ADataSet.Eof do begin [...] ADataSet.FieldByName('MyFieldName1').SomePropertyOrMethod; ADataSet.FieldByName('MyFieldName2').SomePropertyOrMethod; [...] ADataSet.Next; end; &#8230; <a href="http://fgaillard.com/2010/11/fieldbyname-findfield-too-convenient-to-be-honest/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know about you, but I can&#8217;t count anymore the number of times I&#8217;ve seen this code pattern (in code snippets online as well as in production code):</p>
<pre><code><span style="font: 10pt Courier New;"><span class="pas1-space">  </span><span class="pas1-reservedword">while</span><span class="pas1-space"> </span><span class="pas1-reservedword">not</span><span class="pas1-space"> ADataSet</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Eof </span><span class="pas1-reservedword">do
</span><span class="pas1-space">  </span><span class="pas1-reservedword">begin
</span><span class="pas1-space">    </span><span class="pas1-comment">[...]
</span><span class="pas1-space">    ADataSet</span><span class="pas1-symbol">.</span><span class="pas1-identifier">FieldByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'MyFieldName1'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">SomePropertyOrMethod</span><span class="pas1-symbol">;
</span><span class="pas1-space">    ADataSet</span><span class="pas1-symbol">.</span><span class="pas1-identifier">FieldByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'MyFieldName2'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">SomePropertyOrMethod</span><span class="pas1-symbol">;
</span><span class="pas1-space">    </span><span class="pas1-comment">[...]
</span><span class="pas1-space">    ADataSet</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Next</span><span class="pas1-symbol">;
</span><span class="pas1-space">  </span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;</span></span>
</code></pre>
<p>Using FieldByName in a case like this is certainly very convenient and has a lot of <strong>advantages</strong>:<span id="more-365"></span></p>
<ul>
<li><span style="font-size: 15.6px;"><em>Clarity and readability</em>. The intent of the code is obvious and there is no question about which Data point you work with.</span></li>
<li><span style="font-size: 15.6px;"><em>Proximity</em>. You create your Field reference exactly where you need it.</span></li>
<li><span style="font-size: 15.6px;"><em>Flexibility</em>. You&#8217;re not stuck with design-time Fields, your DataSet can represent multiple queries, you just need to know that you have a &#8216;MyFieldName&#8217; column in this context.</span></li>
<li><span style="font-size: 15.6px;"><em>Security</em>. FieldByName never returns nil because it raises an exception if the Field does no exist. So, you&#8217;re sure not to get an AV when directly using a property or method.</span></li>
</ul>
<p>But is has a <strong>major problem</strong>:</p>
<ul>
<li><span style="font-size: 15.6px;">It is searching -again- for the same already found Field at each and every record of the DataSet. Like <strong>this code has Alzheimer</strong>.</span></li>
<li><span style="font-size: 15.6px;">Knowing that each call to FieldByName is mainly a call to FindField, that can <strong>introduce up to 3 new sub-loops within your main loop</strong>. With our 2-Field example above, that&#8217;s 6 sub-loops that can be added for every row.</span></li>
</ul>
<p>It does not seem that bad if it is just an example or some demo code, but as soon as it is published, someone will grab a snippet and a few copy&#8217;n'haste later it ends up in production code.</p>
<p>And indeed, I can tell you that this (untold) company&#8217;s <strong>production code actually contained dozens of cases</strong> like the following (anonymized but real) code:</p>
<pre><code><span style="font: 10pt Courier New;"><span class="pas1-space">  aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">ParamByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'Zone_mask'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">DataType </span><span class="pas1-symbol">:=</span><span class="pas1-space"> ftLargeint</span><span class="pas1-symbol">;
</span><span class="pas1-space">  aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">ParamByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'Zone_mask'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">Value    </span><span class="pas1-symbol">:=</span><span class="pas1-space"> aZoneMask</span><span class="pas1-symbol">;
</span><span class="pas1-space">  aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">ParamByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'Start_date'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">AsDateTime </span><span class="pas1-symbol">:=</span><span class="pas1-space"> fStartDate</span><span class="pas1-symbol">;
</span><span class="pas1-space">  aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">ParamByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'End_date'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">AsDateTime   </span><span class="pas1-symbol">:=</span><span class="pas1-space"> fEndDate</span><span class="pas1-symbol">;

</span><span class="pas1-space">  aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Open</span><span class="pas1-symbol">;
</span><span class="pas1-space">  </span><span class="pas1-reservedword">while</span><span class="pas1-space"> </span><span class="pas1-reservedword">not</span><span class="pas1-space"> aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">EOF </span><span class="pas1-reservedword">do
</span><span class="pas1-space">  </span><span class="pas1-reservedword">begin
</span><span class="pas1-space">    effectiveDeviceInfo </span><span class="pas1-symbol">:=
</span><span class="pas1-space">      TEffectiveDeviceInfo</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Create</span><span class="pas1-symbol">(
</span><span class="pas1-space">         aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">FieldByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'Device_code_name'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">Value</span><span class="pas1-symbol">,
</span><span class="pas1-space">         aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">FieldByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'Device_descr'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">Value</span><span class="pas1-symbol">,
</span><span class="pas1-space">         aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">FieldByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'Toggle_times'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">Value</span><span class="pas1-symbol">,
</span><span class="pas1-space">         aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">FieldByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'Comments'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">Value</span><span class="pas1-symbol">,
</span><span class="pas1-space">         aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">FieldByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'Effective_start_date'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">Value</span><span class="pas1-symbol">,
</span><span class="pas1-space">         aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">FieldByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'Effective_end_date'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">Value</span><span class="pas1-symbol">);

</span><span class="pas1-space">    fChannelDevice</span><span class="pas1-symbol">.</span><span class="pas1-identifier">AddObject</span><span class="pas1-symbol">(
</span><span class="pas1-space">      self</span><span class="pas1-symbol">.</span><span class="pas1-identifier">MakeSortKey</span><span class="pas1-symbol">(
</span><span class="pas1-space">        aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">FieldByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'Device_code_id'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">Value</span><span class="pas1-symbol">,
</span><span class="pas1-space">        aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">FieldByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'Channel_int'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">Value</span><span class="pas1-symbol">),
</span><span class="pas1-space">      effectiveDeviceInfo</span><span class="pas1-symbol">);

</span><span class="pas1-space">    aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Next</span><span class="pas1-symbol">;
</span><span class="pas1-space">  </span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;
</span><span class="pas1-space">  aQuery</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Close</span><span class="pas1-symbol">;</span></span>
</code></pre>
<p>That&#8217;s between 8 and 24 added loops for each record in this dataset which could have tens of thousands of records!<br />
Granted, that would be small loops if the number of fields is reasonable, but still&#8230;</p>
<p>So, I cringe when I see someone posting on StackOverflow a code snippet that looks good (verify Active, DisableControls, try..finally) but has the FieldByName inside the loop:</p>
<pre><code><span style="font: 10pt Courier New;"><span class="pas1-reservedword">begin
</span><span class="pas1-space">  Assert</span><span class="pas1-symbol">(</span><span class="pas1-identifier">AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Active</span><span class="pas1-symbol">,</span><span class="pas1-space"> </span><span class="pas1-string">'Dataset is not active!'</span><span class="pas1-symbol">);
</span><span class="pas1-space">  </span><span class="pas1-reservedword">try
</span><span class="pas1-space">    AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">DisableControls</span><span class="pas1-symbol">;
</span><span class="pas1-space">    AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">First</span><span class="pas1-symbol">;
</span><span class="pas1-space">    </span><span class="pas1-reservedword">while</span><span class="pas1-space"> </span><span class="pas1-reservedword">not</span><span class="pas1-space"> AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Eof </span><span class="pas1-reservedword">do
</span><span class="pas1-space">    </span><span class="pas1-reservedword">begin
</span><span class="pas1-space">      AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Edit</span><span class="pas1-symbol">;
</span><span class="pas1-space">      AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">FieldByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'MyFieldName'</span><span class="pas1-symbol">).</span><span class="pas1-identifier">Value </span><span class="pas1-symbol">:=</span><span class="pas1-space"> Edit1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Text</span><span class="pas1-symbol">;
</span><span class="pas1-space">      AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Post</span><span class="pas1-symbol">;
</span><span class="pas1-space">      AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Next</span><span class="pas1-symbol">;
</span><span class="pas1-space">    </span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;
</span><span class="pas1-space">  </span><span class="pas1-reservedword">finally
</span><span class="pas1-space">    AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">EnableControls</span><span class="pas1-symbol">;
</span><span class="pas1-space">  </span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;
</span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;</span></span>
</code></pre>
<p>And kudos to the poster who changed it after just a little nudge to<strong> create a local Field variable before the loop</strong>. It adds 2 more lines per Field, but the code is much better:</p>
<pre><code><span style="font: 10pt Courier New;"><span class="pas1-reservedword">var
</span><span class="pas1-space">  AField </span><span class="pas1-symbol">:</span><span class="pas1-space"> TField</span><span class="pas1-symbol">;</span><span class="pas1-space">  </span><span class="pas1-comment">// &lt;= line added
</span><span class="pas1-reservedword">begin
</span><span class="pas1-space">  Assert</span><span class="pas1-symbol">(</span><span class="pas1-identifier">AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Active</span><span class="pas1-symbol">,</span><span class="pas1-space"> </span><span class="pas1-string">'Dataset is not active!'</span><span class="pas1-symbol">);
</span><span class="pas1-space">  </span><span class="pas1-reservedword">try
</span><span class="pas1-space">    AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">DisableControls</span><span class="pas1-symbol">;
</span><span class="pas1-space">    AField </span><span class="pas1-symbol">:=</span><span class="pas1-space"> AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">FieldByName</span><span class="pas1-symbol">(</span><span class="pas1-string">'MyFieldName'</span><span class="pas1-symbol">);</span><span class="pas1-space"> </span><span class="pas1-comment">// &lt;= line added
</span><span class="pas1-space">    AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">First</span><span class="pas1-symbol">;
</span><span class="pas1-space">    </span><span class="pas1-reservedword">while</span><span class="pas1-space"> </span><span class="pas1-reservedword">not</span><span class="pas1-space"> AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Eof </span><span class="pas1-reservedword">do
</span><span class="pas1-space">    </span><span class="pas1-reservedword">begin
</span><span class="pas1-space">      AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Edit</span><span class="pas1-symbol">;
</span><span class="pas1-space">      AField</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Value </span><span class="pas1-symbol">:=</span><span class="pas1-space"> Edit1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Text</span><span class="pas1-symbol">;
</span><span class="pas1-space">      AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Post</span><span class="pas1-symbol">;
</span><span class="pas1-space">      AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">Next</span><span class="pas1-symbol">;
</span><span class="pas1-space">    </span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;
</span><span class="pas1-space">  </span><span class="pas1-reservedword">finally
</span><span class="pas1-space">    AdoQuery1</span><span class="pas1-symbol">.</span><span class="pas1-identifier">EnableControls</span><span class="pas1-symbol">;
</span><span class="pas1-space">  </span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;
</span><span class="pas1-reservedword">end</span><span class="pas1-symbol">;</span></span>
</code></pre>
<p>Now, don&#8217;t go &#8220;premature optimization&#8221; on me, as the cases where the number of records is too small to benefit from ousting the FieldByName from the DataSet loop are pretty rare.</p>
<p>I would be curious to know what you get if you do a grep in your code base to find FieldByName or FindField in loops&#8230;<br />
Do you have any?</p>
]]></content:encoded>
			<wfw:commentRss>http://fgaillard.com/2010/11/fieldbyname-findfield-too-convenient-to-be-honest/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>French Delphi Speech Session Material</title>
		<link>http://fgaillard.com/2010/11/french-delphi-speech-session-material/</link>
		<comments>http://fgaillard.com/2010/11/french-delphi-speech-session-material/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 23:30:56 +0000</pubDate>
		<dc:creator>François Gaillard</dc:creator>
				<category><![CDATA[Conference]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Speech]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[VCL]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[CodeWay]]></category>
		<category><![CDATA[ComCtrls]]></category>
		<category><![CDATA[RichEdit]]></category>

		<guid isPermaLink="false">http://fgaillard.com/?p=361</guid>
		<description><![CDATA[A big thanks to all who attended my session on Delphi Speech at CodeWay 4, the French online conference. As promised, I have uploaded the material used for the session: - powerpoint (FR): fgaillard.com/download/Speech_FR.ppt - source code (EN/FR): fgaillard.com/download/Speech_FR_Src.zip Note: &#8230; <a href="http://fgaillard.com/2010/11/french-delphi-speech-session-material/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A big thanks to all who attended my session on Delphi Speech at CodeWay 4, the French online conference.</p>
<p>As promised, I have uploaded the material used for the session:<span id="more-361"></span></p>
<p>- powerpoint (FR): <a href="http://fgaillard.com/download/Speech_FR.ppt">fgaillard.com/download/Speech_FR.ppt</a></p>
<p><a href="http://fgaillard.com/download/Speech_FR.ppt"></a>- source code (EN/FR): <a href="http://fgaillard.com/download/Speech_FR_Src.zip">fgaillard.com/download/Speech_FR_Src.zip</a></p>
<p><strong>Note</strong>: the source code does not include the Speech Type Library (needed for Dictation project), you&#8217;ll have to import it directly in your Delphi.</p>
<p><strong>Disclaimer</strong>: Be warned, the source code is bad and useless&#8230; It might not even have any educational purpose&#8230; Yadda yadda yadda try at your own risk yadda yadda yadda no warranty&#8230; et cetera!</p>
<p>Let me know if there are any problems&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://fgaillard.com/2010/11/french-delphi-speech-session-material/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My Delphi Speech Session in French</title>
		<link>http://fgaillard.com/2010/11/my-delphi-speech-session-in-french/</link>
		<comments>http://fgaillard.com/2010/11/my-delphi-speech-session-in-french/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 06:46:10 +0000</pubDate>
		<dc:creator>François Gaillard</dc:creator>
				<category><![CDATA[Conference]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Speech]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[CodeWay]]></category>
		<category><![CDATA[RichEdit]]></category>

		<guid isPermaLink="false">http://fgaillard.com/?p=359</guid>
		<description><![CDATA[&#8230; is almost now. The agenda for CodeWay 4 has it at 17:00 Paris time. That&#8217;s 8am here in San Francisco and 11am in Quebec and on the East Coast. Here&#8217;s the menu: •Vue d’ensemble •Synthese •Dictee •Contrôle •RichEdit 4.1 &#8230; <a href="http://fgaillard.com/2010/11/my-delphi-speech-session-in-french/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&#8230; is almost now.</p>
<p>The a<a href="http://embarcadero.arrowecs.fr/codeway4_agenda.php" target="_blank">genda for CodeWay 4</a> has it at 17:00 Paris time. That&#8217;s 8am here in San Francisco and 11am in Quebec and on the East Coast.</p>
<p>Here&#8217;s the menu:</p>
<p>•Vue d’ensemble<br />
•Synthese<br />
•Dictee<br />
•Contrôle<br />
•RichEdit 4.1<br />
•Delphi Prism</p>
]]></content:encoded>
			<wfw:commentRss>http://fgaillard.com/2010/11/my-delphi-speech-session-in-french/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft Speech Server 10.2 better than 10.1</title>
		<link>http://fgaillard.com/2010/11/microsoft-speech-server-10-2-better-than-10-1/</link>
		<comments>http://fgaillard.com/2010/11/microsoft-speech-server-10-2-better-than-10-1/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 06:17:20 +0000</pubDate>
		<dc:creator>François Gaillard</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Speech]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[CodeWay]]></category>

		<guid isPermaLink="false">http://fgaillard.com/?p=354</guid>
		<description><![CDATA[As I indicated in this previous post, if you want Text-To-Speech in another language than English, you have to install Microsoft Speech Server. And I gave the link to install the v10.1 I had installed and planned to use for &#8230; <a href="http://fgaillard.com/2010/11/microsoft-speech-server-10-2-better-than-10-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As I indicated in <a href="http://fgaillard.com/2010/11/speech-but-not-in-english/" target="_blank">this previous post</a>, if you want Text-To-Speech in another language than English, you have to install Microsoft Speech Server. And I gave the link to install the v10.1 I had installed and planned to use for my French conference session.</p>
<p>Well, it happened that when I wanted to do the Delphi Prism demo, with the .Net API, it was nowhere to be found on my machine. I tried to install and re-install multiple times the runtime and the SDK: Microsoft.Speech.dll refused to be installed.<span id="more-354"></span></p>
<p>Fortunately, I found the newer 10.2 version, and this one did install correctly and I could record my .Net demo.</p>
<p>Unfortunately, the stupid bug where SpeechSynth is not able to send the audio stream to the standard audio output is still there!</p>
<p>Microsoft Speech Platform Server Runtime v10.2: <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=bb0f72cb-b86b-46d1-bf06-665895a313c7&amp;displaylang=en" target="_blank">http://www.microsoft.com/downloads/en/details.aspx?FamilyID=bb0f72cb-b86b-46d1-bf06-665895a313c7&amp;displaylang=en</a>.</p>
<p>Microsoft Speech Platform SDK v10.2: <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=1b1604d3-4f66-4241-9a21-90a294a5c9a4" target="_blank">http://www.microsoft.com/downloads/en/details.aspx?FamilyID=1b1604d3-4f66-4241-9a21-90a294a5c9a4</a>.</p>
<p>Microsoft Speech Platform languages v10.2: <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=47ffd4e5-e682-4228-8058-dd895252a3c3&amp;displaylang=en" target="_blank">http://www.microsoft.com/downloads/en/details.aspx?FamilyID=47ffd4e5-e682-4228-8058-dd895252a3c3&amp;displaylang=en</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://fgaillard.com/2010/11/microsoft-speech-server-10-2-better-than-10-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

