Mega Code Archive

 
Categories / Delphi / Examples
 

Is pchar[string] ok

Q: Is it ok to cast a string to a pchar? A: Yes. Delphi long strings (the default string type in 32-bit Delphi) are designed specifically to allow typecasting to PChar. The following code is valid (with Delphi 2/3/4): procedure p; var s : string; begin s := 'Hello world'; // set the current window's caption SetWindowText (GetActiveWindow, PChar(s)); end;