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 := 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.