SQLite and Delphi 2009

I created a simple Delphi wrapper for SQLite, the popular open source database library. I’ve just updated it to work with Delphi 2009 – I’m not happy with what I’ve done, because I’ve changed a bunch of declarations from PChar to PAnsiChar and from String to AnsiString, just to get it working quickly. SQLite is fine for Unicode, so the next step is to revise it properly to support Unicode … when I or someone else has time.

It was interesting to do some work with Delphi 2009. It has the old problem: out of date documentation. Here’s what it says about PChar, in the entry on pointer types:

The fundamental types PAnsiChar and PWideChar represent pointers to AnsiChar and WideChar values, respectively. The generic PChar represents a pointer to a Char (that is, in its current implementation, to an AnsiChar).

Further, if you have the following code:

strTest: PChar;
strTest := StrAlloc(6);

and hover the mouse over strTest in the editor, the pop-up tip says:

strTest – System.PAnsiChar

However, this is wrong. In Delphi 2009, a generic PChar is a PWideChar. Here’s the code in SysUtils for StrAlloc:

function StrAlloc(Size: Cardinal): PChar;
  Result := WideStrAlloc(Size);
  Result := AnsiStrAlloc(Size);

UNICODE is defined in Delphi 2009, so StrAlloc returns a PWideChar.

Technorati tags: , ,

3 thoughts on “SQLite and Delphi 2009”

  1. Hi Tim,

    Are you going to be doing a full-on review of D2009 anytime soon? As a long time (and current) D7 user I’m interested to see if its worth making the leap!


Leave a Reply

Your email address will not be published. Required fields are marked *