Link to home
Start Free TrialLog in
Avatar of bnz
bnz

asked on

Empty and null string

Hi
I'm a bit confused when the Win32 sdk talks about that a string should be empty or null.
Could somebody clear things up.

if a pchar is assigned to nil then it is a null string ?
if it's an empty string then ..
ASKER CERTIFIED SOLUTION
Avatar of AvonWyss
AvonWyss
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bugroger
bugroger

Hi,

var
 ts : pchar;

begin
 //before ts set to '' ts is nil = NULL string
 ts := '';
 //after ts set to '' ts is an empty string
 //-> "pointing to a #0"
Avatar of bnz

ASKER

is '' equal #0 ?
bnz, Zero-Terminated strings are terminated by #0. So if you have an empty string, the PChar will therefore point to a #0 (that is, there are no other chars between the beginning of the string and the #0 terminating the string). Because of this, Delphi will substitute '' to a pointer pointing to a #0.
(but be aware that '' on other string types than Zero-Terinated will NOT point to a #0; for instance, the Delphi ANSI strings will be set to nil if '' is assigned!)