<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Ramblings</title>
	
	<link>http://www.jasontpenny.com/blog</link>
	<description>Delphi Programming Observations</description>
	<lastBuildDate>Sat, 07 May 2011 04:36:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/jasontpenny/Delphi" /><feedburner:info uri="jasontpenny/delphi" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Compiling SetVersion.exe with a Delphi before Delphi 2009</title>
		<link>http://feedproxy.google.com/~r/jasontpenny/Delphi/~3/UCaIaOjcUok/</link>
		<comments>http://www.jasontpenny.com/blog/2011/05/06/compiling-setversion-exe-with-a-delphi-before-delphi-2009/#comments</comments>
		<pubDate>Sat, 07 May 2011 04:36:22 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jasontpenny.com/blog/?p=112</guid>
		<description><![CDATA[Compiling SetVersion.exe Several people have emailed me to get a compiled version of SetVersion.exe, or with problems when they try to compile with a version of Delphi before 2009. The developer of the DelphiPackageTool has a compiled version available at http://delphipackageto.svn.sourceforge.net/viewvc/delphipackageto/bin/SetVersion.exe?view=log, you should be able to click the download link on that page. If you [...]]]></description>
			<content:encoded><![CDATA[<h2>Compiling SetVersion.exe</h2>
<p>Several people have emailed me to get a compiled version of SetVersion.exe, or with problems when they try to compile with a version of Delphi before 2009.</p>
<p>The developer of the DelphiPackageTool has a compiled version available at <a href="http://delphipackageto.svn.sourceforge.net/viewvc/delphipackageto/bin/SetVersion.exe?view=log">http://delphipackageto.svn.sourceforge.net/viewvc/delphipackageto/bin/SetVersion.exe?view=log</a>, you should be able to click the download link on that page.</p>
<p>If you would like to compile it yourself, you should be able to follow these steps:</p>
<p>Clone the git repo</p>
<pre class="brush: bash; title: ; notranslate">git clone https://github.com/jasonpenny/democode</pre>
<p>Now you should be able to open the SetVersion.dpr at <span class="identifier">democode/SetVersion/</span></p>
<p>Get the older version of Colin Wilson&#8217;s resource code, go to <a href="http://www.wilsonc.demon.co.uk/">http://www.wilsonc.demon.co.uk/</a> ,<br />
for Delphi 2006 and Delphi 2007: click on Delphi 2006, then download these files</p>
<ul>
<li><a href="http://www.wilsonc.demon.co.uk/files/d10/ImageTypes100.zip">http://www.wilsonc.demon.co.uk/files/d10/ImageTypes100.zip</a></li>
<li><a href="http://www.wilsonc.demon.co.uk/files/d10/ResourceUtils100.zip">http://www.wilsonc.demon.co.uk/files/d10/ResourceUtils100.zip</a></li>
</ul>
<p>Take files from those zip files and replace the same named files at <span class="identifier">democode/Others/ColinWilson/</span></p>
<ul>
<li>ImageTypes100
<ul>
<li>unitEXIcon.pas</li>
</ul>
</li>
<li>ResourceUtils100
<ul>
<li>unitPEFile.pas</li>
<li>unitResFile.pas</li>
<li>unitResourceDetails.pas</li>
<li>unitResourceExaminer.pas</li>
<li>unitResourceGraphics.pas</li>
<li>unitResourceToolbar.pas</li>
<li>unitResourceVersionInfo.pas</li>
</ul>
</li>
</ul>
<p>unitResourceGraphics.pas references <span class="identifier">gifimage</span>, so copy GIFImage.pas from ImageTypes100 to the democode/Others/ColinWilson/ directory and add it to the Delphi project.</p>
<p>Then it should be able to compile.</p>
<h2>Note</h2>
<p>The latest email I received asked how to compile in order to modify the <span class="identifier">product version</span> of the file rather than the <span class="identifier">file version</span>.</p>
<p>Note that there file version and product version are stored as both numbers and strings in the resource. SetVersion.exe currently modifies only the file version stored as numbers. The &#8220;File version&#8221; of an EXE when viewed from the Windows Explorer shows this, but it shows the string representation for &#8220;Product version&#8221;. In order to change the string version, you need to use</p>
<pre class="brush: delphi; title: ; notranslate">VersionInfoResourceDetails.SetKeyValue('ProductVersion', '1234567');</pre>
<img src="http://feeds.feedburner.com/~r/jasontpenny/Delphi/~4/UCaIaOjcUok" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jasontpenny.com/blog/2011/05/06/compiling-setversion-exe-with-a-delphi-before-delphi-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jasontpenny.com/blog/2011/05/06/compiling-setversion-exe-with-a-delphi-before-delphi-2009/</feedburner:origLink></item>
		<item>
		<title>Delphi, Git and the future</title>
		<link>http://feedproxy.google.com/~r/jasontpenny/Delphi/~3/SGQW05iwhQo/</link>
		<comments>http://www.jasontpenny.com/blog/2011/03/16/delphi-git-and-the-future/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 01:39:19 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jasontpenny.com/blog/?p=102</guid>
		<description><![CDATA[I&#8217;m getting more and more hits to this blog for searches including the words &#8220;git&#8221; and &#8220;delphi&#8221;, as well as seeing more Delphi people mention git and use GitHub on twitter and stack overflow. I&#8217;m still happy with using the MSysGit bash console to work with git, but it seems more people are finding Git [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m getting more and more hits to this blog for searches including the words &#8220;git&#8221; and &#8220;delphi&#8221;, as well as seeing more Delphi people mention git and use <a href="https://github.com/">GitHub</a> on twitter and stack overflow.</p>
<p>I&#8217;m still happy with using the MSysGit bash console to work with git, but it seems more people are finding <a href="http://code.google.com/p/gitextensions/">Git Extensions</a> to provide a good experience right in the Windows shell.</p>
<p>There is a project called libgit2 that was started a while ago, and was renewed during last year&#8217;s (2010) Google Summer of Code, and put on <a href="https://github.com/libgit2/libgit2">GitHub/libgit2</a>. It is a library for dealing with git repositories, and can be linked to other code without requiring the other code to also be GPL, which I think is a big plus. It can be compiled into a DLL with Microsoft Visual C++ Express (available from MS at no cost). The project has had a lot of activity lately, with bindings for several languages.</p>
<p>I started a project called <a href="https://github.com/libgit2/GitForDelphi">GitForDelphi</a> to create bindings for Delphi. It currently exposes all the functions exported from libgit2, and I translated some of the unit tests from the libgit2 project. I tried to get all the tests that confirm the functionality rather than internal details, and all the tests that I translated to Delphi are currently passing.</p>
<p>As I said, the libgit2 project is very active, and so far I&#8217;ve only been tracking the exported C API. I don&#8217;t think this is ideal for Delphi users, especially when you come across things like structures with pointers to pointers.  These are easy to deal with in C with array indexing, but it gets a little hairy in Delphi. I intend to hide a lot of the C API in a wrapper class, but I haven&#8217;t figured out just how I want it to look yet; I&#8217;ll probably name it TGitRepository.</p>
<p>If you&#8217;d like to contribute, I&#8217;m on twitter as <a href="http://twitter.com/jasonpenny">@jasonpenny</a>, or fork the <a href="https://github.com/libgit2/GitForDelphi">repo on GitHub</a>.<br />
<span id="more-102"></span></p>
<p>An example of hairy Delphi translation of C code:</p>
<pre class="brush: cpp; title: ; notranslate">entries = (git_index_entry **)index-&gt;entries.contents;

for (i = 0; i &lt; ARRAY_SIZE(TEST_ENTRIES); ++i) {
	git_index_entry *e = entries[TEST_ENTRIES[i].index];

	must_be_true(strcmp(e-&gt;path, TEST_ENTRIES[i].path) == 0);
	must_be_true(e-&gt;mtime.seconds == TEST_ENTRIES[i].mtime);
	must_be_true(e-&gt;file_size == TEST_ENTRIES[i].file_size);
}</pre>
<pre class="brush: delphi; title: ; notranslate">entries := PPgit_index_entry(index.entries.contents);

for i := Low(TEST_ENTRIES) to High(TEST_ENTRIES) do
begin
   // this took me a while to get right
   offset := TEST_ENTRIES[i].index * sizeof(Pgit_index_entry);
   e := PPgit_index_entry(Integer(entries) + offset)^;

   CheckTrue(StrComp(e.path, TEST_ENTRIES[i].path) = 0);
   CheckTrue(e.mtime.seconds = TEST_ENTRIES[i].mtime);
   CheckTrue(e.file_size = TEST_ENTRIES[i].file_size);
end;</pre>
<img src="http://feeds.feedburner.com/~r/jasontpenny/Delphi/~4/SGQW05iwhQo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jasontpenny.com/blog/2011/03/16/delphi-git-and-the-future/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.jasontpenny.com/blog/2011/03/16/delphi-git-and-the-future/</feedburner:origLink></item>
		<item>
		<title>Custom Protocol Handler in Delphi</title>
		<link>http://feedproxy.google.com/~r/jasontpenny/Delphi/~3/qy--dBcFews/</link>
		<comments>http://www.jasontpenny.com/blog/2010/03/23/custom-protocol-handler-in-delphi/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 00:11:08 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jasontpenny.com/blog/?p=94</guid>
		<description><![CDATA[I have wanted to look into creating a custom protocol handler to plug into a TWebBrowser with Delphi for a while, called an Asynchronous Pluggable Protocol. I have seen a few implementations, but they were all quite old, and none did exactly what I wanted, which is to be able to create a temporary APP, [...]]]></description>
			<content:encoded><![CDATA[<p>I have wanted to look into creating a custom protocol handler to plug into a TWebBrowser with Delphi for a while, called an <a href="http://msdn.microsoft.com/en-us/library/aa767916(VS.85).aspx">Asynchronous Pluggable Protocol</a>.  I have seen a few implementations, but they were all quite old, and none did exactly what I wanted, which is to be able to create a temporary <span class="identifier"><em>APP</em></span>, which is local to the application and self contained.</p>
<p><a href="/blog/wp-content/uploads/2010/03/app_screen.png" rel="lightbox" title="Screenshot of Demo program"><img src="/blog/wp-content/uploads/2010/03/app_screen.png" alt="" title="Screenshot" width="700" class="alignnone size-full wp-image-95" /></a><br />
<span id="more-94"></span></p>
<p>From <a href="http://stackoverflow.com/questions/2246192/can-delphi-be-used-to-create-and-handle-a-custom-protocol-handler">this StackOverflow question</a>, I found a basic implementation of a registered <em>APP</em>, at <a href="http://www.doogal.co.uk/plugprot.php">http://www.doogal.co.uk/plugprot.php</a>.  Starting from this, I figured out how to create a temporary asynchronous pluggable protocol.</p>
<p>The way I implemented it allows you to specify a callback <span class="identifier">procedure of object</span> which gets called to handle any URLs for your custom protocol. My implementation allows you to decide the content you return and the MIME type, and also handles POSTs, which I haven&#8217;t seen in other Delphi implementations.</p>
<p>See the AsyncPlugProtoDemo project in <a href="http://github.com/jasonpenny/twebbrowser.utilities">twebbrowser.utilities/AsynchronousPluggableProtocol/</a>.  Note that the code should work with Delphi 2009 and later.  I was able to get it working in Delphi 2007, by changing some <span class="identifier">PChar</span> to <span class="identifier">PWideChar</span>, and <span class="identifier">String</span> to <span class="identifier">WideString</span> where Delphi showed errors, and use <span class="identifier">UTF8Decode()</span> instead of <span class="identifier">UTF8ToString()</span>.</p>
<p><a href="/blog/wp-content/uploads/2010/03/app_post1.png"><img src="/blog/wp-content/uploads/2010/03/app_post1.png" alt="" title="POST screenshot 1" width="700" class="alignnone size-full wp-image-98" /></a></p>
<p><a href="/blog/wp-content/uploads/2010/03/app_post2.png"><img src="/blog/wp-content/uploads/2010/03/app_post2.png" alt="" title="POST screenshot 1" width="700" class="alignnone size-full wp-image-98" /></a></p>
<img src="http://feeds.feedburner.com/~r/jasontpenny/Delphi/~4/qy--dBcFews" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jasontpenny.com/blog/2010/03/23/custom-protocol-handler-in-delphi/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.jasontpenny.com/blog/2010/03/23/custom-protocol-handler-in-delphi/</feedburner:origLink></item>
		<item>
		<title>Updated SetVersion.exe to set File Version info in RES or EXE</title>
		<link>http://feedproxy.google.com/~r/jasontpenny/Delphi/~3/qCwQ04kF9Q0/</link>
		<comments>http://www.jasontpenny.com/blog/2009/09/05/updated-setversion-exe-to-set-file-version-info-in-res-or-exe/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 05:17:12 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Delphi]]></category>

		<guid isPermaLink="false">http://www.jasontpenny.com/blog/2009/09/05/updated-setversion-exe-to-set-file-version-info-in-res-or-exe/</guid>
		<description><![CDATA[My first version of the SetVersion.exe tool to update the Version Information of a Delphi executable allowed you to set the version info stored in a Delphi Resource file (*.RES), which is the main place Delphi stores it.&#160; When you perform a build in Delphi, the version info in the Resource File will override anything [...]]]></description>
			<content:encoded><![CDATA[<p>My first version of the <a href="http://www.jasontpenny.com/blog/2009/05/08/program-to-set-delphi-resource-version-info-from-commandline/">SetVersion.exe</a> tool to update the Version Information of a Delphi executable allowed you to set the version info stored in a Delphi Resource file (*.RES), which is the main place Delphi stores it.&#160; When you perform a build in Delphi, the version info in the Resource File will override anything defined in a *.BDSPROJ or *.DPROJ for the resulting binary (*.EXE, *.DLL).</p>
<p>Now, SetVersion.exe will allow you to set the Version Information on an EXE file after it has been built. See latest code at <a href="http://github.com/jasonpenny/democode/blob/2071571cf5df09343b8ea31a153b7a33d2b33ec2/SetVersion/SetVersion.dpr">github.com/jasonpenny/democode</a></p>
<img src="http://feeds.feedburner.com/~r/jasontpenny/Delphi/~4/qCwQ04kF9Q0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jasontpenny.com/blog/2009/09/05/updated-setversion-exe-to-set-file-version-info-in-res-or-exe/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		<feedburner:origLink>http://www.jasontpenny.com/blog/2009/09/05/updated-setversion-exe-to-set-file-version-info-in-res-or-exe/</feedburner:origLink></item>
		<item>
		<title>SQL Function to Get NVARCHAR FROM UTF-8 Stored in VARCHAR</title>
		<link>http://feedproxy.google.com/~r/jasontpenny/Delphi/~3/Wmf_BqJD0rc/</link>
		<comments>http://www.jasontpenny.com/blog/2009/07/31/sql-function-to-get-nvarchar-from-utf-8-stored-in-varchar/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 03:15:45 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[sql]]></category>
		<category><![CDATA[StarTeam]]></category>

		<guid isPermaLink="false">http://www.jasontpenny.com/blog/?p=78</guid>
		<description><![CDATA[I (am forced to) use StarTeam at work. I think it’s terrible as a Source Code Management system, but I think the Customer Relationship Management aspects (Change Requests, Tasks, Work Records, etc.) work ok. The java GUI client, however, is slow and lacking robust reporting. We certainly have a lot of information stored in StarTeam, [...]]]></description>
			<content:encoded><![CDATA[<p>I (am forced to) use StarTeam at work. I think it’s terrible as a Source Code Management system, but I think the Customer Relationship Management aspects (Change Requests, Tasks, Work Records, etc.) work ok. The java GUI client, however, is slow and lacking robust reporting. We certainly have a lot of information stored in StarTeam, so it would take a really good reason to change to another tool.</p>
<p>So, we have a Delphi program to directly query the SQL views in the MS SQL Server database to perform reporting how we want.&#160; Early on, we ran into some strange characters coming out of the database (things like the leaning quotes that MS Word likes to automatically change).&#160; So I found out that StarTeam was storing UTF-8 in the VARCHAR and TEXT fields, basically treating them like byte arrays.&#160; In Delphi 2009, I can just use <span class="identifier">UTF8ToUnicodeString( RawByteString(queryResultString) );</span> and the output seems to match what is displayed in StarTeam.</p>
<p>Now I’m learning <a href="http://www.asp.net/mvc/">ASP.NET MVC</a> and using LINQ to SQL to read from the StarTeam SQL views. After some searching, the only information that I found was advice against storing UTF-8 in VARCHAR fields, but of course I can’t change the database.</p>
<p>I didn’t want to have to decode the UTF-8 any time I wanted to read the fields from the Model, and I actually did not find a way to decode them properly in C# using LINQ to SQL.</p>
<p>So in my searching, I came across some <a href="http://www.webtoolkit.info/javascript-utf8.html">JavaScript to change ASCII to UTF-8 and back</a>. I then realized that I might be able to translate that to TSQL, to have my own SQL View return NVARCHARs to LINQ to SQL.</p>
<p>And it seems to work: </p>
<p>
<pre class="brush: sql; title: ; notranslate">CREATE FUNCTION dbo.UTF8_TO_NVARCHAR(@in VarChar(MAX))
	RETURNS NVarChar(MAX)
AS
BEGIN
	DECLARE @out NVarChar(MAX), @i int, @c int, @c2 int, @c3 int, @nc int

	SELECT @i = 1, @out = ''

	WHILE (@i &lt;= Len(@in))
	BEGIN
		SET @c = Ascii(SubString(@in, @i, 1))

		IF (@c &lt; 128)
		BEGIN
			SET @nc = @c
			SET @i = @i + 1
		END
		ELSE IF (@c &gt; 191 AND @c &lt; 224)
		BEGIN
			SET @c2 = Ascii(SubString(@in, @i + 1, 1))

			SET @nc = (((@c &amp; 31) * 64 /* &lt;&lt; 6 */) | (@c2 &amp; 63))
			SET @i = @i + 2
		END
		ELSE
		BEGIN
			SET @c2 = Ascii(SubString(@in, @i + 1, 1))
			SET @c3 = Ascii(SubString(@in, @i + 2, 1))

			SET @nc = (((@c &amp; 15) * 4096 /* &lt;&lt; 12 */) | ((@c2 &amp; 63) * 64 /* &lt;&lt; 6 */) | (@c3 &amp; 63))
			SET @i = @i + 3
		END

		SET @out = @out + NChar(@nc)
	END
	RETURN @out
END
GO
</pre>
</p>
<p>I used VARCHAR(Max) so that this Function will work with TEXT fields, as well as VARCHAR fields. I believe VARCHAR(Max) was introduced in SQL Server 2005; it allows you to have a VARCHAR variable longer than 8000 characters.</p>
<img src="http://feeds.feedburner.com/~r/jasontpenny/Delphi/~4/Wmf_BqJD0rc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jasontpenny.com/blog/2009/07/31/sql-function-to-get-nvarchar-from-utf-8-stored-in-varchar/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.jasontpenny.com/blog/2009/07/31/sql-function-to-get-nvarchar-from-utf-8-stored-in-varchar/</feedburner:origLink></item>
		<item>
		<title>Program To Set Delphi Resource Version Info from commandline</title>
		<link>http://feedproxy.google.com/~r/jasontpenny/Delphi/~3/933otayE7Z0/</link>
		<comments>http://www.jasontpenny.com/blog/2009/05/08/program-to-set-delphi-resource-version-info-from-commandline/#comments</comments>
		<pubDate>Sat, 09 May 2009 04:49:46 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[commandline]]></category>

		<guid isPermaLink="false">http://www.jasontpenny.com/blog/?p=75</guid>
		<description><![CDATA[With Delphi&#8217;s decision to move to using MSBuild, building Delphi projects from the commandline became a lot easier, but it lacks a way to set the Version Info on the resultant EXE. Using the code from the XN Resource Editor, it was pretty easy to write a commandline program to change the Version Info stored [...]]]></description>
			<content:encoded><![CDATA[<p>With Delphi&#8217;s decision to move to using MSBuild, building Delphi projects from the commandline became a lot easier, but it lacks a way to set the Version Info on the resultant EXE.</p>
<p>Using the code from the <a href="http://www.wilsonc.demon.co.uk/d10resourceeditor.htm">XN Resource Editor</a>, it was pretty easy to write a commandline program to change the Version Info stored in a Delphi Resource file, SetVersion.exe.  The source code for XN Resource Editor is available at <a href="http://www.wilsonc.demon.co.uk/delphi.htm">http://www.wilsonc.demon.co.uk/delphi.htm</a>.  I found one little problem with the Delphi 2009 version, the RES files were being corrupted after running the SetVersion.exe program, but simply changing a Char and PChar to Byte and PByte fixed it.</p>
<p>Calling the program before calling MSBuild (or DCC32 if you don&#8217;t use the latest Delphi) will allow you to set the Version Info, which will be compiled into the EXE.</p>
<p>See the <a href="http://github.com/jasonpenny/democode/tree/master">github repository</a> for the source code (SetVersion/ directory).  The code only compiles with Delphi2009 (I tried with Delphi 2006 and it failed), but I think it should only take getting the correct version of the XN Resource Editor&#8217;s source code files at <a href="http://www.wilsonc.demon.co.uk/delphi.htm">http://www.wilsonc.demon.co.uk/delphi.htm</a> and dropping them into Others/ColinWilson/.</p>
<img src="http://feeds.feedburner.com/~r/jasontpenny/Delphi/~4/933otayE7Z0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jasontpenny.com/blog/2009/05/08/program-to-set-delphi-resource-version-info-from-commandline/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.jasontpenny.com/blog/2009/05/08/program-to-set-delphi-resource-version-info-from-commandline/</feedburner:origLink></item>
		<item>
		<title>Using DLLs stored as Resources in Delphi programs</title>
		<link>http://feedproxy.google.com/~r/jasontpenny/Delphi/~3/USMxcHThx28/</link>
		<comments>http://www.jasontpenny.com/blog/2009/05/01/using-dlls-stored-as-resources-in-delphi-programs/#comments</comments>
		<pubDate>Sat, 02 May 2009 00:31:13 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[BTMemoryModule]]></category>

		<guid isPermaLink="false">http://www.jasontpenny.com/blog/?p=70</guid>
		<description><![CDATA[There are a few DLLs which my Delphi programs interface to, which were developed in other languages. Using LoadLibrary() and GetProcAddress(), your code can avoid crashing by checking for the existance of the DLL. This also allows storing the DLL as a resource, inside the executable, which you can extract to the filesystem and before [...]]]></description>
			<content:encoded><![CDATA[<p>There are a few DLLs which my Delphi programs interface to, which were developed in other languages. Using <span class="identifier">LoadLibrary()</span> and <span class="identifier">GetProcAddress()</span>, your code can avoid crashing by checking for the existance of the DLL.  This also allows storing the DLL as a resource, inside the executable, which you can extract to the filesystem and before calling LoadLibrary() and GetProcAddress().</p>
<p>Extracting the DLL to the filesystem works, but there is a better way: <span class="identifier">BTMemoryModule</span>.  BTMemoryModule allows you to extract the DLL to a TMemoryStream, and use it as a DLL, with <span class="identifier">BTMemoryLoadLibrary</span> and <span class="identifier">BTMemoryGetProcAddress</span>.<br />
<span id="more-70"></span></p>
<p>By not extracting the DLL to the filesystem, file access security issues are avoided. <a href="http://delphi.about.com/od/windowsshellapi/l/aa012103c.htm">This about.com article</a> suggests outputting the DLL in the same directory as the EXE, which is frowned upon in Windows versions after XP.  I wasn&#8217;t sure if BTMemoryModule would cause problems with Windows Vista UAC, but I haven&#8217;t experienced any.</p>
<p>I have a demo project which demonstrates using BTMemoryModule and dGina.dll to disable the windows taskbar at <a href="http://github.com/jasonpenny/democode/tree/master">GitHub</a> (If you don&#8217;t use Git, or don&#8217;t know what it is, you can click the &#8220;download&#8221; button on the page to download a Zip file).  It compiles (at least) with Delphi 2006, Delphi 2007 and Delphi 2009 (I made minor changes to the BTMemoryModule.pas that I downloaded years ago to work with Delphi2009, but I don&#8217;t remember exactly what had to be changed.  It was minor though).</p>
<img src="http://feeds.feedburner.com/~r/jasontpenny/Delphi/~4/USMxcHThx28" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jasontpenny.com/blog/2009/05/01/using-dlls-stored-as-resources-in-delphi-programs/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://www.jasontpenny.com/blog/2009/05/01/using-dlls-stored-as-resources-in-delphi-programs/</feedburner:origLink></item>
		<item>
		<title>Git and Delphi</title>
		<link>http://feedproxy.google.com/~r/jasontpenny/Delphi/~3/9JBI3Atfs4Y/</link>
		<comments>http://www.jasontpenny.com/blog/2009/04/03/git-and-delphi/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 04:08:50 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://www.jasontpenny.com/blog/?p=52</guid>
		<description><![CDATA[At work, we use Borland Starteam for code management and bug/change tracking. Lately, I have been using Git for code management, in addition. I really like having the benefits of Git, while not forcing the other developers to change how they work. Git can track all my little code changes, and then I checkin to [...]]]></description>
			<content:encoded><![CDATA[<p>At work, we use Borland Starteam for code management and bug/change tracking.  Lately, I have been using <a href="http://git-scm.com/">Git</a> for code management, in addition.  I really like having the benefits of Git, while not forcing the other developers to change how they work.  Git can track all my little code changes, and then I checkin to Starteam to share with the other developers</p>
<p>I keep a Git bash (part of <a href="http://code.google.com/p/msysgit/">mSysGit</a>) shell open all day while I&#8217;m working.  It took a little while to get used to looking at Unix-style diffs (comparison of the last version of a file and what is currently on the disk), but now I definitely prefer it to working in Starteam or with TortoiseSVN which force you to use the mouse.  Also Starteam has the nasty habit of not being able to determine the Status of a file, constantly saying Unknown even after an explicit Refresh (F5) and right click -&gt; Update Status, instead of realizing a file is Current or Modified.</p>
<p><img class="alignnone size-large wp-image-56" title="Delphi and Git Bash" src="http://www.jasontpenny.com/blog/wp-content/uploads/2009/04/delphiandgit-1024x547.png" alt="Delphi and Git Bash" width="700" /><br />
<span id="more-52"></span></p>
<h4>Integration: Starteam, TortoiseSVN vs. commandline</h4>
<p>I read a lot of blog posts where people say they don&#8217;t like git or other similar DVCSes because they don&#8217;t have good visual clients.  I find that I am able to get to the information that I want to a lot easier (and it <a href="http://www.codinghorror.com/blog/archives/001088.html">feels faster</a> whether or not it is).  I alt-Tab from Delphi to my <span class="identifier">Git Bash</span> look at what files have changed, maybe look at what changes have been made, commit the change or revert it, and then alt-Tab back to Delphi.  Git has never gotten confused about a file status, I have seen TortoiseSVN show the wrong icon, and Starteam routinely gets the status wrong, or caches it, or just plain can&#8217;t figure it out.  Using git bash, I can stay at the root of the repository and see that a file was changed 5 sub-directories down, exactly which file it is, and optionally see exactly the changes made. Quickly, without taking my fingers off the keyboard. I&#8217;m assuming you&#8217;re a programmer, if you&#8217;re reading this, and I think that you should be comfortable with the keyboard and a command-line (whether it&#8217;s Windows&#8217; cmd.exe or the linux-like git bash)</p>
<h4>Git is Very Fast</h4>
<p>Git is a DVCS (Distributed Version Control System) which means you can work without a server of any kind.  Git handles this by storing everything in a &#8220;.git&#8221; directory at the root of the repository.  When I was first trying Subversion, it was annoying to see the &#8220;.svn&#8221; directories it creates in each and every subdirectory in the repository. And it only stores the history of the last commit, it has to go back to the svn server to get more; git stores the full history. I can see the whole history or any part of the history with ease.</p>
<p>Lately, I&#8217;ve also been using git for temporary repositories. Often, I will need to create a SQL script for a release. It usually consists of several parts, and when there are quite a few, it can take a while to find the section I&#8217;m actually trying to fix. Now I will create a git repository (all you need to do is <span class="identifier">git init</span>) and work with each piece of the script as a separate file. When the script is working and ready, it gets put into Starteam and the git repository is deleted, quickly and easily (it&#8217;s just a directory of files in .git\).</p>
<h4>Git makes copying between repositories easy</h4>
<p>Starteam&#8217;s sharing model is that it runs a server which clients may connect to in order to retrieve information (change request, task, source code, etc.), since git has no server component, sharing is quite different.  Basically, you tell git to <span class="identifier">pull</span> and <span class="identifier">push</span> to places that you set up as <span class="identifier">remote</span>s.  A <span class="identifier">remote</span> is any other git repository.  I have a remote which goes to a directory hosted by a local IIS server, so my co-workers can <span class="identifier">pull</span> my entire history anytime they want.  I also have a remote on a 4GB USB drive (though it does not need to be very large, the main repository is only 18MB for the last 8 months of history), which allows me to take my full history home with me, without any security issues like hosting something over the internet (except, of course, if I were to lose the USB drive).</p>
<p>The two remotes I have set up are <span class="identifier">bare</span> remotes, meaning they never have files checked-out, they only have the history of the repository (so they&#8217;re only used for pushing and pulling to). You can setup a new bare repository, for instance to an IIS directory:</p>
<pre class="brush: bash; title: ; notranslate">cd \Inetpub\wwwroot\git\
mkdir repo.git
cd repo.git
git --bare init
mv hooks/post-update.noexec hooks/post-update # this allows the repository to be pulled correctly over HTTP</pre>
<p>then you add the <span class="identifier">remote</span> to your repository, for instance if your code is at C:\code\</p>
<pre class="brush: bash; title: ; notranslate">cd \code\
git remote add public \Inetpub\wwwroot\git\repo.git
git push public master</pre>
<p>now whenever you want to make all your changes available to others, you just have to <span class="identifier">git push public</span></p>
<h4>Open source sharing, free and easy with GitHub</h4>
<p>There are many options for sharing code with others on the internet.  So far, I&#8217;ve been creating a zip-file of my code and making it available to download from my website.  I think it works fine, unless I find a problem and want to change it.  Also, if someone just wants to look at the code, they have to download and unzip the file.  I haven&#8217;t spent a lot of time with it, but GitHub makes a lot of this easier and better.  It is free to sign up and put open source code (you can put closed-source code, accessible only to whom you say so, but the plans cost money); it uses git, so it has the full history of the code, and is very easy to update (if you set it up following a tutorial like <a href="http://kylecordes.com/2008/04/30/git-windows-go/">this</a>, you just need to <span class="identifier">git push</span>); and it allows anyone to navigate the directory structure and view text files right from the website.</p>
<p>I have made my code from this blog available <a href="http://github.com/jasonpenny/twebbrowser.utilities/tree/master">in this repository</a>.</p>
<p>I only wish more people using Delphi would use GitHub.</p>
<img src="http://feeds.feedburner.com/~r/jasontpenny/Delphi/~4/9JBI3Atfs4Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jasontpenny.com/blog/2009/04/03/git-and-delphi/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.jasontpenny.com/blog/2009/04/03/git-and-delphi/</feedburner:origLink></item>
		<item>
		<title>JQuery and TableSorter in a TWebBrowser</title>
		<link>http://feedproxy.google.com/~r/jasontpenny/Delphi/~3/dTjmO-keMY8/</link>
		<comments>http://www.jasontpenny.com/blog/2009/02/07/jquery-and-tablesorter-in-a-twebbrowser/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 06:47:16 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[twebbrowser]]></category>

		<guid isPermaLink="false">http://www.jasontpenny.com/blog/?p=45</guid>
		<description><![CDATA[As a follow up to my first post on JQuery in a TWebBrowser, I wanted to add the JQuery plugin TableSorter to an HTML report in order to add interactive sorting. Again, I wanted the program to be fully self-contained, so I didn&#8217;t want to add any &#60;script&#62; tags referring to temp files or anything [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="lightbox" title="JQueryTableSorterTest Screenshot" href="http://www.jasontpenny.com/blog/wp-content/uploads/2009/02/jquerytablesortertest.png"><img class="alignnone size-medium wp-image-46" title="JQueryTableSorterTest Screenshot" src="http://www.jasontpenny.com/blog/wp-content/uploads/2009/02/jquerytablesortertest-300x189.png" alt="JQueryTableSorterTest Screenshot" width="300" height="189" /></a></p>
<p>As a follow up to my first post on <a href="http://www.jasontpenny.com/blog/2008/11/21/jquery-in-a-twebbrowser-in-a-self-contained-delphi-app/">JQuery in a TWebBrowser</a>, I wanted to add the JQuery plugin <a href="http://tablesorter.com">TableSorter</a> to an HTML report in order to add interactive sorting. Again, I wanted the program to be fully self-contained, so I didn&#8217;t want to add any <span class="identifier">&lt;script&gt;</span> tags referring to temp files or anything like that.</p>
<p><a href="/Delphi/JQueryTableSorterTest.zip">Download the Delphi project</a> which injects JQuery, JQuery plugin cssRule and JQuery plugin TableSorter.  I tested that it works with Delphi 2006 and Delphi 2009.<br />
<span id="more-45"></span></p>
<p>In order to use the TableSorter plugin, basically you just have to call the <span class="identifier">tablesorter()</span> function on the table object, so after injecting JQuery and the TableSorter plugin, if you have a table with an id of &#8220;<span class="identifier">t1</span>&#8220;:</p>
<pre class="brush: jscript; title: ; notranslate">
   $(&quot;#t1&quot;).tablesorter();
</pre>
<p>This allows you to click on a header element, and it will sort the data elements, but it doesn&#8217;t show any indication of what is currently sorted.</p>
<p>The TableSorter plugin will add the CSS class headerSortDown or headerSortUp depending on the last sort performed, so we just need to set some CSS.</p>
<p>Of course, I didn&#8217;t want to have to output images as temp files either.  You can refer to EXE resources from a TWebBrowser by &#8220;res://ExeName/ResourceType/Resourcename&#8221; (see <a href="http://www.bsalsa.com/protocols.html">http://www.bsalsa.com/protocols.html</a>).  So if you have a resource of an image named <span class="identifier">IMAGEBG</span> in an EXE named test.exe:<br />
resources.rc<br />
<span class="identifier">IMAGEBG  23 &#8220;bg.gif&#8221;</span><br />
you can use &lt;img src=&#8221;res://test.exe/IMAGEBG&#8221; /&gt; to output an image (23 is the default resource type, so it can be left out. If the resource was defined as <span class="identifier">IMAGEBG  GIF &#8220;bg.gif&#8221;</span>, you would refer to it as res://test.exe/gif/IMAGEBG).</p>
<p>I didn&#8217;t want this CSS in the HTML either, so I found the <a href="http://plugins.jquery.com/project/jquerycssrule">cssRule JQuery plugin</a>, which allows you to set CSS rules easily from JavaScript.  The only problem is that it splits strings on &#8220;:&#8221;, which caused problems with specifying a background-url of &#8220;res://ExeName/Resourcename&#8221;.  I chose to replace &#8220;:&#8221; with &#8220;|&#8221;, and then I modified <span class="identifier">jquery.cssRule.js</span> on line 137 to change &#8220;|&#8221; back to &#8220;:&#8221;, so the code splitting on &#8220;:&#8221; doesn&#8217;t have a problem.</p>
<p>With this, the TableSorter injected into a TWebBrowser is finished.  You can view the source of the HTML document, and there is no mention of a script or CSS.</p>
<img src="http://feeds.feedburner.com/~r/jasontpenny/Delphi/~4/dTjmO-keMY8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jasontpenny.com/blog/2009/02/07/jquery-and-tablesorter-in-a-twebbrowser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jasontpenny.com/blog/2009/02/07/jquery-and-tablesorter-in-a-twebbrowser/</feedburner:origLink></item>
		<item>
		<title>Google Maps in a TWebBrowser from Delphi: Directions</title>
		<link>http://feedproxy.google.com/~r/jasontpenny/Delphi/~3/OLoutdD67P0/</link>
		<comments>http://www.jasontpenny.com/blog/2009/01/11/google-maps-in-a-twebbrowser-from-delphi-directions/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 05:04:20 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[twebbrowser]]></category>

		<guid isPermaLink="false">http://www.jasontpenny.com/blog/?p=28</guid>
		<description><![CDATA[The GoogleMaps API has a GDirections object which can be used to retrieve directions between points.  Full JavaScript applications are possible, but interaction with Delphi allows further possibilities.  Previous demo programs showed how to call JavaScript from Delphi, this demo also allows the JavaScript to call Delphi functions (using JavaScript&#8217;s external object, explained later). The [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.jasontpenny.com/blog/wp-content/uploads/2009/01/googlemapsdirectionstest.png" rel="lightbox"><img class="size-medium wp-image-29" title="GoogleMapsDirectionsTest.exe" src="http://www.jasontpenny.com/blog/wp-content/uploads/2009/01/googlemapsdirectionstest-300x224.png" alt="Screenshot" width="300" height="224" /></a></p>
<p>The GoogleMaps API has a GDirections object which can be used to retrieve directions between points.  Full JavaScript applications are possible, but interaction with Delphi allows further possibilities.  Previous demo programs showed how to call JavaScript from Delphi, this demo also allows the JavaScript to call Delphi functions (using JavaScript&#8217;s <span class="identifier">external</span> object, explained later).</p>
<p>The <a href="/Delphi/GoogleMapsDirectionsTest.zip">demo program</a> allows you to enter two or three addresses, and will retrieve the directions with the GoogleMaps API.  The directions will be sent to Delphi from JavaScript, and they will be displayed in a TListBox.  Clicking on an item in the TListBox will show the map &#8220;blowup&#8221; (a zoomed in box for a step, as seen in the screenshot above).</p>
<p><span id="more-28"></span></p>
<p>I borrowed mainly from 3 places for this demo.  <a href="http://econym.googlepages.com/index.htm">Google Maps API Tutorial</a> for some JavaScript and using GDirections, <a href="http://www.delphidabbler.com/articles?article=18">How to customise the TWebBrowser user interface</a> and <a href="http://www.stevetrefethen.com/blog/CallingWindowsClientCodeFromJavascriptHostedInsideTheWebBrowserControl.aspx">Calling Windows Client code from Javascript hosted inside the WebBrowser control</a> which is implemented in his demo program <a href="http://www.stevetrefethen.com/files/googlemap.zip">googlemap.zip</a>.  The source code files which I did not write are included in my demo zip file in a subdirectory &#8220;Others&#8221;.</p>
<p>I think the JavaScript code using <span class="identifier">GDirections</span> is pretty self explanatory.  When you click the button, a callback is assigned for the &#8220;load&#8221; event, which runs through the returned Waypoints and the steps associated to the waypoints and calls the Delphi functions with <span class="identifier">external</span>.</p>
<p>The TWebBrowser is customized so that the greyed-out scrollbar is not shown, since we are resizing the map to always fill the full size of the TWebBrowser, and I prefer the look without the 3D border.  These are made available from the TWBContainer class in OthersUContainer.pas.</p>
<p>I created a class TWBGoogleMaps in uWBGoogleMaps.pas which is mostly just to keep the code for working with the TWebBrowser and GoogleMaps separate from the main program code.  It sets the defaults for the scrollbar and 3D border, as well as re-implements <span class="identifier">GetExternal</span> of the IDocHostUIHandler (which gives the TWebBrowser an IDispatch interface for use with <span class="identifier">external</span>).</p>
<p>The way I understand it, when the TWebBrowser executes <span class="identifier">external</span> in JavaScript, it asks the Host for an IDispatch with IDocHostUIHandler.GetExternal.  So if your exe exposes a COM interface, then it allows the JavaScript to call Delphi functions.  I prefer not to have to define an actual COM object and create a TLB, and everything that entails, so I used the Automation.pas from Steve Trefethen&#8217;s VCLMap demo (linked above as googlemap.zip).  If you are using Delphi 7 or below, I believe you have to go the COM interface and TLB route as I remember reading somewhere that the TObjectDispatch doesn&#8217;t work or doesn&#8217;t exist for older versions.  You can get more information for implementing the <span class="identifier">external</span> object using a COM inferface <a href="http://www.delphidabbler.com/articles?article=22">here</a>.  My demo code works for me with Delphi 2006, Delphi 2007 and Delphi 2009.</p>
<p>Using Steve Trefethen&#8217;s Automation.pas simplifies things a lot.  First you need to define the interface, as in what <span class="identifier">external</span> in JavaScript is allowed to call.  I created a class which defines procedures <span class="identifier">NewDirections</span> which will clear any existing directions, <span class="identifier">AddWaypoint</span> which sets up a new Waypoint, <span class="identifier">AddStep</span> which adds a step to the last Waypoint added, and <span class="identifier">CopyRight</span> which adds the directions&#8217; CopyRight information and signals that all Waypoints and Steps have been added.</p>
<pre class="brush: delphi; title: ; notranslate">TExtJavaScript = class(TObjectWrapper)
published
   procedure NewDirections;
   procedure AddWaypoint(const aLocation, aAddress,
      aRouteDistanceHTML, aRouteDurationHTML: String);
   procedure AddStep(const aLocation, aStepDescriptionHTML,
      aStepDistanceHTML: String);

   procedure CopyRight(const aValue: String);
end;
</pre>
<p>Second, you have to return the TAutoObjectDispatch object when the TWebBrowser asks for the External IDispatch.  I implemented the GetExternal in the TWBGoogleMaps class to call the OnGetExternal event, so we set that, and in the event create and return the TObjectWrapper class and the TAutoObjectDispatch:</p>
<pre class="brush: delphi; title: ; notranslate">procedure TfrmDirections.FormCreate(Sender: TObject);
begin
   fWBGoogleMaps := TWBGoogleMaps.Create(WebBrowser1);
   fWBGoogleMaps.OnGetExternal := WBOnGetExternal;
   ...
end;

// and then
function TfrmDirections.WBOnGetExternal(
   out ppDispatch: IDispatch): HResult;
var
   W: TExtJavaScript;
begin
   W := TExtJavaScript.Connect(Forms.Application);
   ppDispatch :=
      TAutoObjectDispatch.Create(W) as IDispatch;
   Result := S_OK;
end;
</pre>
<p>The rest of the code is just for demonstration purposes.</p>
<p>Let me know what you think.</p>
<img src="http://feeds.feedburner.com/~r/jasontpenny/Delphi/~4/OLoutdD67P0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jasontpenny.com/blog/2009/01/11/google-maps-in-a-twebbrowser-from-delphi-directions/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		<feedburner:origLink>http://www.jasontpenny.com/blog/2009/01/11/google-maps-in-a-twebbrowser-from-delphi-directions/</feedburner:origLink></item>
	</channel>
</rss>

