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:

var
strTest: PChar;
begin
strTest := StrAlloc(6);
strcopy(strTest,’Hello’);
strdispose(strTest);
end;

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;
begin
{$IFDEF UNICODE}
  Result := WideStrAlloc(Size);
{$ELSE}
  Result := AnsiStrAlloc(Size);
{$ENDIF}
end;

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!

    Gary

  2. Where can I get WideStrAlloc and AnsiStrAlloc functions? Do you have both to send me?

Comments are closed.