Ramblings

Delphi Programming Observations

Source Code License About Contact

Friday, May 6, 2011

Compiling SetVersion.exe with a Delphi before Delphi 2009

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 would like to compile it yourself, you should be able to follow these steps:

Clone the git repo

git clone https://github.com/jasonpenny/democode

Now you should be able to open the SetVersion.dpr at democode/SetVersion/

Get the older version of Colin Wilson’s resource code, go to http://www.wilsonc.demon.co.uk/ ,
for Delphi 2006 and Delphi 2007: click on Delphi 2006, then download these files

Take files from those zip files and replace the same named files at democode/Others/ColinWilson/

  • ImageTypes100
    • unitEXIcon.pas
  • ResourceUtils100
    • unitPEFile.pas
    • unitResFile.pas
    • unitResourceDetails.pas
    • unitResourceExaminer.pas
    • unitResourceGraphics.pas
    • unitResourceToolbar.pas
    • unitResourceVersionInfo.pas

unitResourceGraphics.pas references gifimage, so copy GIFImage.pas from ImageTypes100 to the democode/Others/ColinWilson/ directory and add it to the Delphi project.

Then it should be able to compile.

Note

The latest email I received asked how to compile in order to modify the product version of the file rather than the file version.

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 “File version” of an EXE when viewed from the Windows Explorer shows this, but it shows the string representation for “Product version”. In order to change the string version, you need to use

VersionInfoResourceDetails.SetKeyValue('ProductVersion', '1234567');
posted by Jason at 11:36 pm  

Wednesday, March 16, 2011

Delphi, Git and the future

I’m getting more and more hits to this blog for searches including the words “git” and “delphi”, as well as seeing more Delphi people mention git and use GitHub on twitter and stack overflow.

I’m still happy with using the MSysGit bash console to work with git, but it seems more people are finding Git Extensions to provide a good experience right in the Windows shell.

There is a project called libgit2 that was started a while ago, and was renewed during last year’s (2010) Google Summer of Code, and put on GitHub/libgit2. 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.

I started a project called GitForDelphi 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.

As I said, the libgit2 project is very active, and so far I’ve only been tracking the exported C API. I don’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’t figured out just how I want it to look yet; I’ll probably name it TGitRepository.

If you’d like to contribute, I’m on twitter as @jasonpenny, or fork the repo on GitHub.
(more…)

posted by Jason at 8:39 pm  

Tuesday, March 23, 2010

Custom Protocol Handler in Delphi

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, which is local to the application and self contained.


(more…)

posted by Jason at 7:11 pm  

Saturday, September 5, 2009

Updated SetVersion.exe to set File Version info in RES or EXE

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.  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).

Now, SetVersion.exe will allow you to set the Version Information on an EXE file after it has been built. See latest code at github.com/jasonpenny/democode

posted by Jason at 12:17 am  

Friday, July 31, 2009

SQL Function to Get NVARCHAR FROM UTF-8 Stored in VARCHAR

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.

So, we have a Delphi program to directly query the SQL views in the MS SQL Server database to perform reporting how we want.  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).  So I found out that StarTeam was storing UTF-8 in the VARCHAR and TEXT fields, basically treating them like byte arrays.  In Delphi 2009, I can just use UTF8ToUnicodeString( RawByteString(queryResultString) ); and the output seems to match what is displayed in StarTeam.

Now I’m learning ASP.NET MVC 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.

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.

So in my searching, I came across some JavaScript to change ASCII to UTF-8 and back. 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.

And it seems to work:

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 <= Len(@in))
	BEGIN
		SET @c = Ascii(SubString(@in, @i, 1))

		IF (@c < 128)
		BEGIN
			SET @nc = @c
			SET @i = @i + 1
		END
		ELSE IF (@c > 191 AND @c < 224)
		BEGIN
			SET @c2 = Ascii(SubString(@in, @i + 1, 1))

			SET @nc = (((@c & 31) * 64 /* << 6 */) | (@c2 & 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 & 15) * 4096 /* << 12 */) | ((@c2 & 63) * 64 /* << 6 */) | (@c3 & 63))
			SET @i = @i + 3
		END

		SET @out = @out + NChar(@nc)
	END
	RETURN @out
END
GO

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.

posted by Jason at 10:15 pm  

Friday, May 8, 2009

Program To Set Delphi Resource Version Info from commandline

With Delphi’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 in a Delphi Resource file, SetVersion.exe. The source code for XN Resource Editor is available at http://www.wilsonc.demon.co.uk/delphi.htm. 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.

Calling the program before calling MSBuild (or DCC32 if you don’t use the latest Delphi) will allow you to set the Version Info, which will be compiled into the EXE.

See the github repository 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’s source code files at http://www.wilsonc.demon.co.uk/delphi.htm and dropping them into Others/ColinWilson/.

posted by Jason at 11:49 pm  

Friday, May 1, 2009

Using DLLs stored as Resources in Delphi programs

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 calling LoadLibrary() and GetProcAddress().

Extracting the DLL to the filesystem works, but there is a better way: BTMemoryModule. BTMemoryModule allows you to extract the DLL to a TMemoryStream, and use it as a DLL, with BTMemoryLoadLibrary and BTMemoryGetProcAddress.
(more…)

posted by Jason at 7:31 pm  

Friday, April 3, 2009

Git and Delphi

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 Starteam to share with the other developers

I keep a Git bash (part of mSysGit) shell open all day while I’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 -> Update Status, instead of realizing a file is Current or Modified.

Delphi and Git Bash
(more…)

posted by Jason at 11:08 pm  

Saturday, February 7, 2009

JQuery and TableSorter in a TWebBrowser

JQueryTableSorterTest Screenshot

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’t want to add any <script> tags referring to temp files or anything like that.

Download the Delphi project which injects JQuery, JQuery plugin cssRule and JQuery plugin TableSorter. I tested that it works with Delphi 2006 and Delphi 2009.
(more…)

posted by Jason at 1:47 am  

Sunday, January 11, 2009

Google Maps in a TWebBrowser from Delphi: Directions

Screenshot

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’s external object, explained later).

The demo program 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 “blowup” (a zoomed in box for a step, as seen in the screenshot above).

(more…)

posted by Jason at 12:04 am  
Next Page »

Powered by WordPress