Do delphi automatically process string string parameters if different string encodings are used?

In other words: does this work, i.e. Is the encoding of the parameter taken into account when generating the result of the Unicode string?

function Test: string;
var
  Pattern: string;
  Parameter: UTF8String;
begin
  // ...
  Result := Format(Pattern, [Parameter]);
end;

Or do you need to explicitly specify the parameters?

Result := Format(Pattern, [string(Parameter)]);

Due to open parameters, the compiler does not give any hints or warnings ...

+5
source share
1 answer

format is an array of const, so in the first case it is assumed that tutf8string will be passed, and in the second case, tunicodestring is passed to the assembler procedure.

So, the second part is transforming forces and, of course, in order.

, ansistring " const" .

, wideformatbuf(), , cvtansistr cvtansistring, , unicodestring.

format() . , , -, .

, wideformatbuf . @WStrFromLStr cvtansistr (sysutils.pas: 10208 D2009).

: UTF-8 .

:

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;


 var u,u2 : string;
    a   :utf8string;  
 begin
    a:='asrfdsfsd';
    u:=format('%s',[a]); // breakpoint here
 end.

, "debug dcu's" f7/f8/f9. !

+5

All Articles