<?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>DELPHI AREA</title>
	<atom:link href="http://www.delphiarea.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.delphiarea.com</link>
	<description>DELPHI AREA is a Delphi resource website offering freeware and open source Delphi components, packages, and applications.  DELPHI AREA has also a forum to discuss and answer the questions about Delphi programming.</description>
	<lastBuildDate>Tue, 28 Jun 2011 17:34:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Gradient v2.71 Released</title>
		<link>http://www.delphiarea.com/articles/gradient-v2_71/</link>
		<comments>http://www.delphiarea.com/articles/gradient-v2_71/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 17:34:07 +0000</pubDate>
		<dc:creator>Kambiz</dc:creator>
				<category><![CDATA[Site's News]]></category>
		<category><![CDATA[Gradient Component]]></category>

		<guid isPermaLink="false">http://www.delphiarea.com/?p=212</guid>
		<description><![CDATA[The Gradient Component v2.71 has been released. [bugfix] Fixed bug in saving ColorEnd property [bugfix] Fixed bug in drawing non-rectangular shape gradients in Delphi 2010 and probably Delphi 2009.]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.delphiarea.com/products/delphi-components/gradient/">Gradient Component</a> v2.71 has been released.<span id="more-212"></span></p>
<ul>
<li>[bugfix] Fixed bug in saving <code>ColorEnd</code> property</li>
<li>[bugfix] Fixed bug in drawing non-rectangular shape gradients in Delphi 2010 and probably Delphi 2009.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.delphiarea.com/articles/gradient-v2_71/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Print Preview v5.70 Released</title>
		<link>http://www.delphiarea.com/articles/preview-v5_70/</link>
		<comments>http://www.delphiarea.com/articles/preview-v5_70/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 17:29:08 +0000</pubDate>
		<dc:creator>Kambiz</dc:creator>
				<category><![CDATA[Site's News]]></category>
		<category><![CDATA[Print Preview Components]]></category>

		<guid isPermaLink="false">http://www.delphiarea.com/?p=211</guid>
		<description><![CDATA[The Print Preview Components v5.70 has been released. [bugfix] Fixed the GDI+ issue when it is used inside a dll (read more). [bugfix] Fixed the incorrect scrolling direction using mouse wheel. [feature] For convenience, added BeginAppend and EndAppend methods for adding a new page at the end of pages. These methods are simply a wrapper [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.delphiarea.com/products/delphi-components/preview/">Print Preview Components</a> v5.70 has been released.<span id="more-211"></span></p>
<ul>
<li>[bugfix] Fixed the GDI+ issue when it is used inside a dll (<a href="http://www.delphiarea.com/articles/preview-v5_60/#comments">read more</a>).</li>
<li>[bugfix] Fixed the incorrect scrolling direction using mouse wheel.</li>
<li>[feature] For convenience, added <code>BeginAppend</code> and <code>EndAppend</code> methods for adding a new page at the end of pages. These methods are simply a wrapper around <code>BeginInsert</code> and <code>EndInsert</code> methods.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.delphiarea.com/articles/preview-v5_70/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Gradient v2.70 Released</title>
		<link>http://www.delphiarea.com/articles/gradient-v2_70/</link>
		<comments>http://www.delphiarea.com/articles/gradient-v2_70/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 21:06:10 +0000</pubDate>
		<dc:creator>Kambiz</dc:creator>
				<category><![CDATA[Site's News]]></category>
		<category><![CDATA[Gradient Component]]></category>

		<guid isPermaLink="false">http://www.delphiarea.com/?p=210</guid>
		<description><![CDATA[The Gradient Component v2.70 has been released. [feature] Like standard TShape control, the shape of TGradient control can be determined using the new Shape property.]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.delphiarea.com/products/delphi-components/gradient/">Gradient Component</a> v2.70 has been released.<span id="more-210"></span></p>
<ul>
<li>[feature] Like standard TShape control, the shape of TGradient control can be determined using the new <code>Shape</code> property.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.delphiarea.com/articles/gradient-v2_70/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The i18n package v1.1 Released</title>
		<link>http://www.delphiarea.com/articles/i18n-v1_1/</link>
		<comments>http://www.delphiarea.com/articles/i18n-v1_1/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 01:39:35 +0000</pubDate>
		<dc:creator>Kambiz</dc:creator>
				<category><![CDATA[Site's News]]></category>
		<category><![CDATA[i18n Package]]></category>

		<guid isPermaLink="false">http://www.delphiarea.com/?p=209</guid>
		<description><![CDATA[the i18n package v1.1 has bean released. This is a bug fix update. [bugfix] &#8211; Made the package compatible with Delphi 2009. However, the package has some problems on Delphi 2009: Because of a few bugs in Controls unit, mirroring page and tab controls for right-to-left languages causes child controls of these controls go off [...]]]></description>
			<content:encoded><![CDATA[<p> the <a href="http://www.delphiarea.com/products/delphi-packages/i18n/">i18n package</a> v1.1 has bean released. This is a bug fix update.<span id="more-209"></span></p>
<ul>
<li>[bugfix] &#8211; Made the package compatible with Delphi 2009. However, the package has some problems on Delphi 2009: Because of a few bugs in Controls unit, mirroring page and tab controls for right-to-left languages causes child controls of these controls go off the screen. Some other common controls may also show odd behavior when toggle the layout&#8217;s direction.</li>
<li>[bigfix] Fixed display problem of the date picker control on Windows XP.</li>
<li>[feature] Some minor tweaks.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.delphiarea.com/articles/i18n-v1_1/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>The i18n Package Released</title>
		<link>http://www.delphiarea.com/articles/i18n-v1/</link>
		<comments>http://www.delphiarea.com/articles/i18n-v1/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 23:16:22 +0000</pubDate>
		<dc:creator>Kambiz</dc:creator>
				<category><![CDATA[Site's News]]></category>
		<category><![CDATA[i18n Package]]></category>

		<guid isPermaLink="false">http://www.delphiarea.com/?p=208</guid>
		<description><![CDATA[Finally the i18n package has bean released. This package contains a set of components for localizing Delphi applications. The i18n package makes the localization of applications an easy task for the Delphi developers. You just need to drop a component on each form and select which properties and string literals/constants should be translated. Then at [...]]]></description>
			<content:encoded><![CDATA[<p>Finally the <a href="http://www.delphiarea.com/products/delphi-packages/i18n/">i18n package</a> has bean released. This package contains a set of components for localizing Delphi applications.<span id="more-208"></span></p>
<p>The i18n package makes the localization of applications an easy task for the Delphi developers. You just need to drop a component on each form and select which properties and string literals/constants should be translated. Then at runtime, just by changing value of a property you can change the locale of your application on the fly. </p>
<p>In the i18n package, changing locale is not only changing the strings of the user interface. It includes displaying numbers and date-time values in local format and native digits, supporting local calendar system, and mirroring the reading layout of the application for right-to-left languages.</p>
<p>Please visit the <a href="http://www.delphiarea.com/products/delphi-packages/i18n/">i18n package</a> page to find out more about this package.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.delphiarea.com/articles/i18n-v1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Graph v2.80 Released</title>
		<link>http://www.delphiarea.com/articles/simplegraph-v2_8/</link>
		<comments>http://www.delphiarea.com/articles/simplegraph-v2_8/#comments</comments>
		<pubDate>Thu, 02 Jun 2011 16:13:06 +0000</pubDate>
		<dc:creator>Kambiz</dc:creator>
				<category><![CDATA[Site's News]]></category>
		<category><![CDATA[Simple Graph Component]]></category>

		<guid isPermaLink="false">http://www.delphiarea.com/?p=198</guid>
		<description><![CDATA[The Simple Graph Component v2.80 has been released. [feature] Added two new options gloFixedAnchorStartPoint and gloFixedAnchorEndPoint to the LinkOptions property of the TGraphLink class. These options control whether the hooked links should be anchored to a fixed point on the target object or not.]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.delphiarea.com/products/delphi-components/simplegraph/">Simple Graph Component</a> v2.80 has been released.<span id="more-198"></span></p>
<ul>
<li>[feature] Added two new options <code>gloFixedAnchorStartPoint</code> and <code>gloFixedAnchorEndPoint</code> to the <code>LinkOptions</code> property of the <code>TGraphLink</code> class. These options control whether the hooked links should be anchored to a fixed point on the target object or not.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.delphiarea.com/articles/simplegraph-v2_8/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Real-Time Marquee v3.2 Released</title>
		<link>http://www.delphiarea.com/articles/marquee-v3_2/</link>
		<comments>http://www.delphiarea.com/articles/marquee-v3_2/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 11:52:57 +0000</pubDate>
		<dc:creator>Kambiz</dc:creator>
				<category><![CDATA[Site's News]]></category>
		<category><![CDATA[Real-Time Marquee Component]]></category>

		<guid isPermaLink="false">http://www.delphiarea.com/?p=196</guid>
		<description><![CDATA[The Real-Time Marquee Component v3.2 has been released. [feature] Before, each marquee item had its own image cache for HTML images. Now, all marquee items use a single image cache to prevent creating/loading images more than once. [bugfix] Fixed bug in EncodeHTMLEntities function of SimpleHTML unit. The function was encoding only one special character and [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.delphiarea.com/products/delphi-components/marquee/">Real-Time Marquee Component</a> v3.2 has been released.<span id="more-196"></span></p>
<ul>
<li>[feature] Before, each marquee item had its own image cache for HTML images. Now, all marquee items use a single image cache to prevent creating/loading images more than once.</li>
<li>[bugfix] Fixed bug in <code>EncodeHTMLEntities</code> function of <code>SimpleHTML</code> unit. The function was encoding only one special character and ignoring the rest.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.delphiarea.com/articles/marquee-v3_2/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Print Preview v5.61 Released</title>
		<link>http://www.delphiarea.com/articles/preview-v5_61/</link>
		<comments>http://www.delphiarea.com/articles/preview-v5_61/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 09:30:06 +0000</pubDate>
		<dc:creator>Kambiz</dc:creator>
				<category><![CDATA[Site's News]]></category>
		<category><![CDATA[Print Preview Components]]></category>

		<guid isPermaLink="false">http://www.delphiarea.com/?p=195</guid>
		<description><![CDATA[The Print Preview Components v5.61 has been released. [bugfix] Fixed the GDI+ issue when it is used inside a dll (read more). [bugfix] In some cases, resizing TPrintPreview control was not updating the visible area marker of the selected thumbnail. [feature] Added DisableTheme property to TThumbnailPreview control. Windows Aero makes the selected thumbnail unclear. By [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.delphiarea.com/products/delphi-components/preview/">Print Preview Components</a> v5.61 has been released.<span id="more-195"></span></p>
<ul>
<li>[bugfix] Fixed the GDI+ issue when it is used inside a dll (<a href="http://www.delphiarea.com/articles/preview-v5_60/#comments">read more</a>).</li>
<li>[bugfix] In some cases, resizing <code>TPrintPreview</code> control was not updating the visible area marker of the selected thumbnail.</li>
<li>[feature] Added <code>DisableTheme</code> property to <code>TThumbnailPreview</code> control. Windows Aero makes the selected thumbnail unclear. By setting this property to true, you can prevent this problem.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.delphiarea.com/articles/preview-v5_61/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>WP-RecentCategoryPosts v1.1 Released</title>
		<link>http://www.delphiarea.com/articles/wp-recentcategoryposts-v1_1/</link>
		<comments>http://www.delphiarea.com/articles/wp-recentcategoryposts-v1_1/#comments</comments>
		<pubDate>Sat, 30 Oct 2010 16:10:20 +0000</pubDate>
		<dc:creator>Kambiz</dc:creator>
				<category><![CDATA[Site's News]]></category>
		<category><![CDATA[WP-RecentCategoryPosts Plugin]]></category>

		<guid isPermaLink="false">http://www.delphiarea.com/?p=194</guid>
		<description><![CDATA[The WP-RecentCategoryPosts plugin v1.1 has been released. This is an upgrade release. [feature] Added an option to show/hide date of posts.]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.delphiarea.com/products/wordpress-plugins/wp-recentcategoryposts/">WP-RecentCategoryPosts</a> plugin v1.1 has been released. This is an upgrade release.<span id="more-194"></span></p>
<ul>
<li>[feature] Added an option to show/hide date of posts.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.delphiarea.com/articles/wp-recentcategoryposts-v1_1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to match two strings approximately</title>
		<link>http://www.delphiarea.com/articles/how-to-match-two-strings-approximately/</link>
		<comments>http://www.delphiarea.com/articles/how-to-match-two-strings-approximately/#comments</comments>
		<pubDate>Sun, 24 Oct 2010 00:54:06 +0000</pubDate>
		<dc:creator>Kambiz</dc:creator>
				<category><![CDATA[Delphi Articles]]></category>
		<category><![CDATA[String Manipulation]]></category>

		<guid isPermaLink="false">http://www.delphiarea.com/?p=189</guid>
		<description><![CDATA[By engaging approximate string matching in our applications, we have this opportunity to write more intelligent and more user friendly applications. In this post, you will find the Delphi implementation of Damerau-Levenshtein distance algorithm to use for writing another Delphi function for fuzzy matching of two strings.]]></description>
			<content:encoded><![CDATA[<p>To implement a function for approximate string matching, we need a reasonable <a href="http://en.wikipedia.org/wiki/String_metric" target="_blank">metric</a> to know how similar two strings are. I decided to use <a href="http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance" target="_blank">Damerau-Levenshtein distance</a> as the metric to achieve the goal.</p>
<h4>Damerau-Levenshtein Distance</h4>
<p>The Damerau-Levenshtein distance is defined as the minimum number of primitive edit operations needed to transform one string into the other, and these operations are substitution, deletion, insertion, and the transposition of two adjacent characters.</p>
<blockquote><p><code>A<u>B</u>C &rarr; A<u>X</u>C &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Substitution<br />
A<u>B</u>C &rarr; AC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Deletion<br />
ABC &rarr; AB<u>X</u>C &nbsp;&nbsp;&nbsp;&nbsp; Insertion<br />
A<u>BC</u> &rarr; A<u>CB</u> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Transposition</code></p></blockquote>
<p>Here is the Delphi implementation of Damerau-Levenshtein distance algorithm:</p>

<div class="wp_syntax"><div class="code"><pre class="delphi" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> DamerauLevenshteinDistance<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Str1<span style="color: #000066;">,</span> Str2<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: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">var</span>
  LenStr1<span style="color: #000066;">,</span> LenStr2<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
  I<span style="color: #000066;">,</span> J<span style="color: #000066;">,</span> T<span style="color: #000066;">,</span> Cost<span style="color: #000066;">,</span> Minimum<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
  pStr1<span style="color: #000066;">,</span> pStr2<span style="color: #000066;">,</span> S1<span style="color: #000066;">,</span> S2<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">PChar</span><span style="color: #000066;">;</span>
  D<span style="color: #000066;">,</span> RowPrv2<span style="color: #000066;">,</span> RowPrv1<span style="color: #000066;">,</span> RowCur<span style="color: #000066;">,</span> Temp<span style="color: #000066;">:</span> PIntegerArray<span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">begin</span>
  LenStr1 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">Length</span><span style="color: #000066;">&#40;</span>Str1<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  LenStr2 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">Length</span><span style="color: #000066;">&#40;</span>Str2<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #808080; font-style: italic;">// to save some space, make sure the second index points to the shorter string</span>
  <span style="color: #000000; font-weight: bold;">if</span> LenStr1 &lt; LenStr2 <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #000000; font-weight: bold;">begin</span>
    T <span style="color: #000066;">:</span><span style="color: #000066;">=</span> LenStr1<span style="color: #000066;">;</span>
    LenStr1 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> LenStr2<span style="color: #000066;">;</span>
    LenStr2 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> T<span style="color: #000066;">;</span>
    pStr1 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066; font-weight: bold;">PChar</span><span style="color: #000066;">&#40;</span>Str2<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    pStr2 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066; font-weight: bold;">PChar</span><span style="color: #000066;">&#40;</span>Str1<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: #000000; font-weight: bold;">begin</span>
    pStr1 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066; font-weight: bold;">PChar</span><span style="color: #000066;">&#40;</span>Str1<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    pStr2 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066; font-weight: bold;">PChar</span><span style="color: #000066;">&#40;</span>Str2<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: #808080; font-style: italic;">// to save some time and space, look for exact match </span>
  <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #000066;">&#40;</span>LenStr2 &lt;&gt; <span style="color: #0000ff;">0</span><span style="color: #000066;">&#41;</span> <span style="color: #000000; font-weight: bold;">and</span> <span style="color: #000066;">&#40;</span>pStr1<span style="color: #000066;">^</span> <span style="color: #000066;">=</span> pStr2<span style="color: #000066;">^</span><span style="color: #000066;">&#41;</span> <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">begin</span>
    <span style="color: #000066;">Inc</span><span style="color: #000066;">&#40;</span>pStr1<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000066;">Inc</span><span style="color: #000066;">&#40;</span>pStr2<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000066;">Dec</span><span style="color: #000066;">&#40;</span>LenStr1<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    <span style="color: #000066;">Dec</span><span style="color: #000066;">&#40;</span>LenStr2<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: #808080; font-style: italic;">// when one string is empty, length of the other is the distance</span>
  <span style="color: #000000; font-weight: bold;">if</span> LenStr2 <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>
    Result <span style="color: #000066;">:</span><span style="color: #000066;">=</span> LenStr1<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: #808080; font-style: italic;">// calculate the edit distance</span>
  T <span style="color: #000066;">:</span><span style="color: #000066;">=</span> LenStr2 <span style="color: #000066;">+</span> <span style="color: #0000ff;">1</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">GetMem</span><span style="color: #000066;">&#40;</span>D<span style="color: #000066;">,</span> <span style="color: #0000ff;">3</span> <span style="color: #000066;">*</span> T <span style="color: #000066;">*</span> <span style="color: #000066;">SizeOf</span><span style="color: #000066;">&#40;</span><span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">FillChar</span><span style="color: #000066;">&#40;</span>D<span style="color: #000066;">^</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">2</span> <span style="color: #000066;">*</span> T <span style="color: #000066;">*</span> <span style="color: #000066;">SizeOf</span><span style="color: #000066;">&#40;</span><span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span> <span style="color: #0000ff;">0</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  RowCur <span style="color: #000066;">:</span><span style="color: #000066;">=</span> D<span style="color: #000066;">;</span>
  RowPrv1 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">@</span>D<span style="color: #000066;">&#91;</span>T<span style="color: #000066;">&#93;</span><span style="color: #000066;">;</span>
  RowPrv2 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">@</span>D<span style="color: #000066;">&#91;</span><span style="color: #0000ff;">2</span> <span style="color: #000066;">*</span> T<span style="color: #000066;">&#93;</span><span style="color: #000066;">;</span>
  S1 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> pStr1<span style="color: #000066;">;</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> LenStr1 <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #000000; font-weight: bold;">begin</span>
    Temp <span style="color: #000066;">:</span><span style="color: #000066;">=</span> RowPrv2<span style="color: #000066;">;</span>
    RowPrv2 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> RowPrv1<span style="color: #000066;">;</span>
    RowPrv1 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> RowCur<span style="color: #000066;">;</span>
    RowCur <span style="color: #000066;">:</span><span style="color: #000066;">=</span> Temp<span style="color: #000066;">;</span>
    RowCur<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: #000066;">=</span> I<span style="color: #000066;">;</span>
    S2 <span style="color: #000066;">:</span><span style="color: #000066;">=</span> pStr2<span style="color: #000066;">;</span>
    <span style="color: #000000; font-weight: bold;">for</span> J <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> LenStr2 <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">begin</span>
      Cost <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">Ord</span><span style="color: #000066;">&#40;</span>S1<span style="color: #000066;">^</span> &lt;&gt; S2<span style="color: #000066;">^</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
      Minimum <span style="color: #000066;">:</span><span style="color: #000066;">=</span> RowPrv1<span style="color: #000066;">&#91;</span>J <span style="color: #000066;">-</span> <span style="color: #0000ff;">1</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">+</span> Cost<span style="color: #000066;">;</span>      <span style="color: #808080; font-style: italic;">// substitution</span>
      T <span style="color: #000066;">:</span><span style="color: #000066;">=</span> RowCur<span style="color: #000066;">&#91;</span>J <span style="color: #000066;">-</span> <span style="color: #0000ff;">1</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">+</span> <span style="color: #0000ff;">1</span><span style="color: #000066;">;</span>                <span style="color: #808080; font-style: italic;">// insertion</span>
      <span style="color: #000000; font-weight: bold;">if</span> T &lt; Minimum <span style="color: #000000; font-weight: bold;">then</span>
        Minimum <span style="color: #000066;">:</span><span style="color: #000066;">=</span> T<span style="color: #000066;">;</span>
      T <span style="color: #000066;">:</span><span style="color: #000066;">=</span> RowPrv1<span style="color: #000066;">&#91;</span>J<span style="color: #000066;">&#93;</span> <span style="color: #000066;">+</span> <span style="color: #0000ff;">1</span><span style="color: #000066;">;</span>                   <span style="color: #808080; font-style: italic;">// deletion</span>
      <span style="color: #000000; font-weight: bold;">if</span> T &lt; Minimum <span style="color: #000000; font-weight: bold;">then</span>
        Minimum <span style="color: #000066;">:</span><span style="color: #000066;">=</span> T<span style="color: #000066;">;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000066;">&#40;</span>I &lt;&gt; <span style="color: #0000ff;">1</span><span style="color: #000066;">&#41;</span> <span style="color: #000000; font-weight: bold;">and</span> <span style="color: #000066;">&#40;</span>J &lt;&gt; <span style="color: #0000ff;">1</span><span style="color: #000066;">&#41;</span> <span style="color: #000000; font-weight: bold;">and</span> <span style="color: #000066;">&#40;</span>S1<span style="color: #000066;">^</span> <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>S2 <span style="color: #000066;">-</span> <span style="color: #0000ff;">1</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">^</span><span style="color: #000066;">&#41;</span> <span style="color: #000000; font-weight: bold;">and</span> <span style="color: #000066;">&#40;</span>S2<span style="color: #000066;">^</span> <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>S1 <span style="color: #000066;">-</span> <span style="color: #0000ff;">1</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">^</span><span style="color: #000066;">&#41;</span> <span style="color: #000000; font-weight: bold;">then</span>
      <span style="color: #000000; font-weight: bold;">begin</span>
        T <span style="color: #000066;">:</span><span style="color: #000066;">=</span> RowPrv2<span style="color: #000066;">&#91;</span>J <span style="color: #000066;">-</span> <span style="color: #0000ff;">2</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">+</span> Cost<span style="color: #000066;">;</span>          <span style="color: #808080; font-style: italic;">// transposition</span>
        <span style="color: #000000; font-weight: bold;">if</span> T &lt; Minimum <span style="color: #000000; font-weight: bold;">then</span>
          Minimum <span style="color: #000066;">:</span><span style="color: #000066;">=</span> T<span style="color: #000066;">;</span>
      <span style="color: #000000; font-weight: bold;">end</span><span style="color: #000066;">;</span>
      RowCur<span style="color: #000066;">&#91;</span>J<span style="color: #000066;">&#93;</span> <span style="color: #000066;">:</span><span style="color: #000066;">=</span> Minimum<span style="color: #000066;">;</span>
      <span style="color: #000066;">Inc</span><span style="color: #000066;">&#40;</span>S2<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: #000066;">Inc</span><span style="color: #000066;">&#40;</span>S1<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>
  Result <span style="color: #000066;">:</span><span style="color: #000066;">=</span> RowCur<span style="color: #000066;">&#91;</span>LenStr2<span style="color: #000066;">&#93;</span><span style="color: #000066;">;</span>
  <span style="color: #000066;">FreeMem</span><span style="color: #000066;">&#40;</span>D<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>Because <code>DamerauLevenshteinDistance</code> function is normally called inside a loop, I had to optimize my implementation. Otherwise, the original algorithm is smaller and more readable.</p>
<h4>Similarity Ratio</h4>
<p>Now that we have a function to find out how similar two strings are, we can use it to calculate the similarity ratio of the two strings to approximately match them.</p>

<div class="wp_syntax"><div class="code"><pre class="delphi" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> StringSimilarityRatio<span style="color: #000066;">&#40;</span><span style="color: #000000; font-weight: bold;">const</span> Str1<span style="color: #000066;">,</span> Str2<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">String</span><span style="color: #000066;">;</span> IgnoreCase<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: #000066; font-weight: bold;">Double</span><span style="color: #000066;">;</span>
<span style="color: #000000; font-weight: bold;">var</span>
  MaxLen<span style="color: #000066;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span><span style="color: #000066;">;</span>
  Distance<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> <span style="color: #0000ff;">1.0</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000066;">Length</span><span style="color: #000066;">&#40;</span>Str1<span style="color: #000066;">&#41;</span> &gt; <span style="color: #000066;">Length</span><span style="color: #000066;">&#40;</span>Str2<span style="color: #000066;">&#41;</span> <span style="color: #000000; font-weight: bold;">then</span>
    MaxLen <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">Length</span><span style="color: #000066;">&#40;</span>Str1<span style="color: #000066;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">else</span>
    MaxLen <span style="color: #000066;">:</span><span style="color: #000066;">=</span> <span style="color: #000066;">Length</span><span style="color: #000066;">&#40;</span>Str2<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
  <span style="color: #000000; font-weight: bold;">if</span> MaxLen &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>
    <span style="color: #000000; font-weight: bold;">if</span> IgnoreCase <span style="color: #000000; font-weight: bold;">then</span>
      Distance <span style="color: #000066;">:</span><span style="color: #000066;">=</span> DamerauLevenshteinDistance<span style="color: #000066;">&#40;</span><span style="color: #000066;">LowerCase</span><span style="color: #000066;">&#40;</span>Str1<span style="color: #000066;">&#41;</span><span style="color: #000066;">,</span> <span style="color: #000066;">LowerCase</span><span style="color: #000066;">&#40;</span>Str2<span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">else</span>
      Distance <span style="color: #000066;">:</span><span style="color: #000066;">=</span> DamerauLevenshteinDistance<span style="color: #000066;">&#40;</span>Str1<span style="color: #000066;">,</span> Str2<span style="color: #000066;">&#41;</span><span style="color: #000066;">;</span>
    Result <span style="color: #000066;">:</span><span style="color: #000066;">=</span> Result <span style="color: #000066;">-</span> <span style="color: #000066;">&#40;</span>Distance <span style="color: #000066;">/</span> MaxLen<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>

<p>The return value of <code>StringSimilarityRatio</code> function is a floating-point number between 0 (zero) and 1 (one), where 0 means not similar at all and 1 means equal strings.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.delphiarea.com/articles/how-to-match-two-strings-approximately/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.722 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-05-17 16:37:58 -->
<!-- Compression = gzip -->
