Is there a difference and what type of between PAnsiChar and PChar? (in Delphi previous 2007)
Thank you, in advance!
I take notice of the "In Delphi previous 2007" in your question, which I take to mean "In Delphi 2007 and earlier", so....
In Delphi 2007 and previous PChar and PANSIChar are synonymous. They mean the same thing - a pointer to an ANSIChar value. Char is synonymous with ANSIChar in those versions.
However, in Delphi 2009 and later, Char becomes synonymous with WideChar, so PChar becomes synonymous with PWideChar.
Note, that a WideChar is NOT a Unicode character - Unicode is simply not that straightforward. Any one WideChar value may be a codepoint in the BMP (Basic Multilingual Plane) or it may be either one of a surrogate-pair. It may also be a diacritical mark - for example an "accent" to be applied to the immediately preceding codepoint in a WideString.
The concept of a "character" in Unicode does not easily map to a single value of any type.
Delphi 2009 Character types are Char, AnsiChar and WideChar, where Char defaults to WideChar. In previous versions of Delphi, a Char would be equivalent to an AnsiChar. The P is to indicate a pointer to the given type.
PAnsiChar is pointer to non-unicode char (old string type), while PChar points to new style, unicode char.
PChar is a pointer to a "char", whatever that happens to be. In D2009 and later, Char means a UnicodeChar. Before that, Char was an AnsiChar.
The difference is that if you're using D2007 and migrate to a later version, the definition of PChar will change, while the definition of PAnsiChar will not.
In D2009 and later: yes, there is. PChar
is a pointer to a Char
which is a unicode character (a WideChar
). And PAnsiChar
is a pointer to a AnsiChar
, which is - as the name implies - an ANSI character.
EDIT: For pre-2009 versions of Delphi PChar
and PAnsiChar
are exactly the same. They both point to an (Ansi) character.