Search code examples
stringdelphiwidechar

Convert PWideChar to String. Should I use WideCharToString?


I am using Delphi XE3.

In the following codes:

procedure TForm1.Button1Click(Sender: TObject);
var
  A: PWideChar;
  B: string;
  C: string;
begin
  A := '123';

  B := A;
  C := WideCharToString(A);
end;

It seems that both direct assignment and WideCharToString can convert PWideChar to string. In such a case, why anyone will use WideCharToString to do the conversion?

Thanks


Solution

  • Both operations call _UStrFromPWChar routine from system.pas, so work similarly.

    Somebody might prefer explicit function call rather than implicit conversion to be sure what really happens.