How do I convert a PAnsiChar
variable to WideString
or to string
?
You simply assign one variable to another and let the Delphi compiler do all the conversion for you:
var
p: PAnsiChar;
s: string;
w: WideString;
....
s := p;
w := p;
If you want to convert in the other direction, and restricting the discussion to Delphi 7 for which Char, PChar, string are all ANSI data types you would use the following:
PAnsiChar(s);
PAnsiChar(AnsiString(w));
The casts are needed when going in this direction and in the case of the WideString the data must be explicitly converted from Unicode to ANSI before asking for a null-terminated C string pointer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With