The Wiert Corner – Jeroen Pluimers’ irregular stream of Wiert stuff

on .NET, C#, Delphi, databases, and personal interests

  • Twitter Updates

  • My work

  • My badges

  • My Flickr Stream

    DSC_5228

    DSC_5227

    DSC_5226

    More Photos
  • Pages

  • All categories

  • Email Subscription

    Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Delphi 2010 build numbers don’t tell you what you have installed

Posted by jpluimers on 2009/12/17

I applied update 4 and 5 and the boost update.
Since I didn’t know the exact state my Delphi 2010 was in, I watched the build numbers and the list of items in the Help About box.
Read the rest of this entry »

Posted in Delphi, Development | 1 Comment »

Delphi – MD5: the MessageDigest_5 unit has been there since Delphi 2007

Posted by jpluimers on 2009/12/11

I still see a lot of people crafting their own MD5 implementation.
A lot of the existing MD5 implementations do not work well in Delphi 2009 and later (because they need to be adapted to Unicode).
Many of those existing implementations behave differently if you pass the same ASCII characters as AnsiString or UnicodeString.

The MessageDigest_5 unit has been available in Delphi since Delphi 2007.
This is the location relative to your installation directory: source\Win32\soap\wsdlimporter\MessageDigest_5.pas

So this unit used by the WSDL, and more importantly: works with Unicode (if you pass it a string with Unicode characters, it will convert them to UTF-8 first).
The unit is not in your default search path, and has not been very well promoted (the only link at the Embarcadero site was an article by Pawel Glowacki), so few people know about it.

Now you know too :-)

Note that MD5 is normally used to hash binary data.
It is not wise to send a non ASCII string through both the AnsiString and UnicodeString versions: because of the different encoding (and therefore a different binary representation), you will get different results depending on the Delphi version used.

A sample of the usage showing the above AnsiString/UnicodeString issue is not present for ASCII strings, nor for ANSI strings: this is because both get encoded using UTF-8 before hashing.
Delphi 2007 did not do the UTF-8 encoding, so you will see different results here.
You will also see that Writeln uses the Console for encoding, and those are different than the code editor.

Edit: 20091216 – added RawByteString example to show that the conversion does not matter.

program md5;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  MessageDigest_5 in 'C:\Program Files\Embarcadero\RAD Studio\7.0\source\Win32\soap\wsdlimporter\MessageDigest_5.pas';
  // Vista/Windows 7: MessageDigest_5 in 'C:\Program Files (x86)\Embarcadero\RAD Studio\7.0\source\Win32\soap\wsdlimporter\MessageDigest_5.pas';

function GetMd5(const Value: AnsiString): string; overload;
var
  hash: MessageDigest_5.IMD5;
  fingerprint: string;
begin
  hash := MessageDigest_5.GetMD5();
  hash.Update(Value);
  fingerprint := hash.AsString();
  Result := LowerCase(fingerprint);
end;

function GetMd5(const Value: UnicodeString): string; overload;
var
  hash: MessageDigest_5.IMD5;
  fingerprint: string;
begin
  hash := MessageDigest_5.GetMD5();
  hash.Update(Value);
  fingerprint := hash.AsString();
  Result := LowerCase(fingerprint);
end;

var
  SourceAnsiString: AnsiString;
  SourceUnicodeString: UnicodeString;
  SourceRawByteString: RawByteString;

begin
  try
    SourceAnsiString := 'foobar';
    SourceUnicodeString := 'foobar';
    SourceRawByteString := 'foobar';

    Writeln(GetMd5(SourceAnsiString));
    Writeln(GetMd5(SourceUnicodeString));
    Writeln(GetMd5(SourceRawByteString));

    SourceAnsiString := 'föøbår';
    SourceUnicodeString := 'föøbår';
    SourceRawByteString := 'föøbår';
    Writeln(SourceAnsiString, ' ', GetMd5(SourceAnsiString));
    Writeln(SourceUnicodeString, ' ', GetMd5(SourceUnicodeString));
    Writeln(SourceRawByteString, ' ', GetMd5(SourceRawByteString));
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

–jeroen

Posted in Delphi, Development, Encoding, Software Development, UTF-8, UTF8 | 14 Comments »

Phone SPAM: Random Digit Dialing

Posted by jpluimers on 2009/12/10

Just learned something new this evening: ‘Random Digit Dialing’.

A few minutes ago, I got called on an unlisted phone numberby a Dutch company offering money and a kind of lottery mechanism if I was going to take part in their surveys.
In other words: phone SPAM.

They call with a shielded phone number.
So there is no way I can distinguish them from friends that do have a legitimate reason for having an unlisted phone number.

The company that called told me that the only way to avoid these calls was to list all my info that they should not contact me at in some central database, even if the info was already unlisted in the first place.
The world up side down!

And to top it off: Now that they have contacted me, they have the phone number, so I’m bound to be called there again by them.

–jeroen

Posted in About, Personal | Leave a Comment »

Fiddler replaying requests to the ASP.NET Development Server: XP works but Vista not, or “when localhost is not 127.0.0.1 in Fiddler 2″

Posted by jpluimers on 2009/12/09

Today, I bumped into something utterly strange: requests replayed through Fiddler 2 to a locally running ASP.NET Development Server on Vista using localhost URLs did not give a connection.

I use ASP.NET from both C# and Delphi Prism. Most of my development work is on Windows XP (see notes below) but I test on many platforms.
Moving one of the projects from XP to Vista, and testing with Fiddler, I found that when using Fiddler 2:

This form of URL fails on Vista, but works on XP: http://localhost:49703
This form of URL works both on Vista, and XPhttp://127.0.0.1:49703

So on Vista – contrary to XP – localhost requests from Fiddler were in fact being sent to the external network adapter on Vista, and the 127.0.0.1 requests to the internal network adapter.
Since the ASP.NET Development Server is bound only to the internal network adapter, external requests don’t work (boy, I wish they did, it would make some of my debugging so much easier!).

Read the rest of this entry »

Posted in .NET, ASP.NET, C#, Delphi, Development, Prism, Software Development | 2 Comments »

TIFF preview in GMail now works (was: GMail + TIFF = ? « Scientia potentia est « The Wiert Corner – Jeroen Pluimers’ irregular stream of Wiert stuff)

Posted by jpluimers on 2009/12/08

in GMail, TIFF preview suport has started working again!

Which means that I know can read incoming FAX messages in the preview window in stead of saving and viewing them in an external tool.

It probably means that the bug here is fixed:

GMail + TIFF = ? « Scientia potentia est « The Wiert Corner – Jeroen Pluimers’ irregular stream of Wiert stuff.

–jeroen

Posted in GMail, Google | Leave a Comment »

Foto’s speciale dienst “Kerk der Friezen” online

Posted by jpluimers on 2009/12/07

Toen we afgelopen maand tussen de verbouwing door even in Rome waren, had ik op zondag 15 november een bijzonder mogelijkheid om foto’s te nemen in de Kerk der Friezen (ook Friezenker genoemd) tijdens de dienst ter ere van het opleveren van de restauratie. Read the rest of this entry »

Posted in About, Personal, Travel | Leave a Comment »

Le Vosgien du Net · Switch between versions of Firebird SQL Server

Posted by jpluimers on 2009/12/05

This is very handy on testing your software on multiple versions of FireBird.
Now someone that expands this to InterBase as well :-)

Le Vosgien du Net · Switch between versions of Firebird SQL Server.

–jeroen

Posted in Database Development, Development, Firebird, InterBase | 2 Comments »

Official Google Webmaster Central Blog: How fast is your site?

Posted by jpluimers on 2009/12/05

Just so I remember if I ever need it:

Official Google Webmaster Central Blog: How fast is your site?.

–jeroen

Posted in Development, Web Development | Leave a Comment »

InterBase 2007: UPPER and collations (and a trick to specify the character set for string literals)

Posted by jpluimers on 2009/12/01

One of the applications that I’m currently involved with will in the future be used in different European countries.

Since it is developed in Delphi 2007, and uses InterBase 2007 we have chosen to use the ISO8859_15 character set: it is a single byte character set very similar to ISO8859_1, but supports the euro sign (€) and some other characters (Š, š, Ž, ž, Œ, œ and Ÿ).

When testing, we found out that UPPER would not always function as we expected.
Hence below some explanation about how UPPER behaves depending on the character sets and collation sequences you specify.

Note: most of this also holds for other versions of InterBase and for FireBird versions, but I have not checked everything with all versions yet, FireBird might be different as this piece of documentation shows.
If anyone does have the results for other InterBase or FireBird versions, please let me know the results.

Read the rest of this entry »

Posted in Database Development, Delphi, Development, Firebird, InterBase | Leave a Comment »

Generating EAN-13 barcode EPS files for your article numbers

Posted by jpluimers on 2009/11/30

Recently, I needed a bunch of EPS files for EAN-13 barcodes (that’s the kind of barcodes European companies put on their products).

Terry  Burton wrote a great barcode writer in pure PostScript for this, with a simple web front end to generate a barcode one at a time.

Actually, his tool can:

  • Generate all kinds of 1D and 2D barcodes (EAN-5, -8, -13, Code 128, Code 39, Code 93, Data Matrix, GS1, ISBN and many may more)
  • Generate the check digits where needed

Since most DTP packages favour EPS over PS, and I needed more than just a few of them, I went a bit beyond the one-at-a-time simple web front end.

In fact, the EPS file generated by Terry Burton’s web front end has just one variable: the article number.

Basically, there are two ways go generate a whole bunch of the barcode EPS files:

  1. Grab one EPS file from his site and search/replace the article number in it (do! it’s easy, read on)
  2. Encode the parameters in the URL on his web-site, and extract the link to the (random location of the) EPS file, then download the EPS file (don’t! costs a lot of time and burdens his web-server)

Let’s see how easy 1. is… Read the rest of this entry »

Posted in Development, EPS/PostScript | 1 Comment »