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: , ,

Related posts:

  1. Using SQLite 3 with Unicode in Delphi
  2. Updated SQLite wrapper for Embarcadero Delphi (and Free Pascal)
  3. What’s new in Delphi 2009
  4. Delphi and C++ Builder 2009 are available to order
  5. Extend SQLite with Delphi functions

3 comments to SQLite and Delphi 2009