I understand that in Delphi, an empty string (AnsiString or WideString) can be represented by a nil pointer, or by a pointer to an actual empty string.
By experiment I’ve shown that in Delphi XE2 (with particular compiler settings) PChar('') <> nil. But is this guaranteed, or might it change in a future version, or be dependent on some compiler setting?
I’m having a crisis of confidence. If anyone can give me a definitive answer I’d be grateful.
Yes. Type casts from string literals to PChar will never be null pointers. Type casts from strings of the same character type to PChar won’t be null, either. (String to PChar, AnsiString to PAnsiChar, etc.)
Type casts of other things to PChar may be null, though. (Pointer to PChar, AnsiString to PWideChar, etc.)
The documentation covers this in the Mixing Delphi Strings and Null-Terminated Strings section of the String Types topic: