title: What's the correct way to assign PAnsiChar to a (unicode-) string?
body: <p>I have got a DLL function that returns a pointer to ANSI text (PAnsiChar). I want to assign this to a (unicode-) string (This is Delphi XE2.). The following compiles but I get a warning
  "W1057 Implicit String cast from 'AnsiChar' to 'string'":</p>
  
  <pre><code>function TProj4.pj_strerrno(_ErrorCode: Integer): string;
  var
    Err: PAnsiChar;
  begin
    Err := Fpj_strerrno(_ErrorCode);
    Result := Err;
  end;
  </code></pre>
  
  <p>EDIT: The text in question is an error message in English, so there are unlikely to be any conversion problems here.</p>
  
  <p>I am now tempted to just explicitly typecast Err to string like this ...</p>
  
  <pre><code>Result := String(Err);
  </code></pre>
  
  <p>.. to get rid of the warning. Could this go wrong? Should I rather use a temporary AnsiString variable instead?</p>
  
  <pre><code>var
    s: AnsiString;
  [...]
  s := Err;
  Result := String(s);
  </code></pre>
  
  <p>If yes, why?</p>
  
  <p>Or should I make it explicit, that the code first converts a PAnsiChar to AnsiString and then the AnsiString to a String?</p>
  
  <pre><code>Result := String(AnsiString(Err));
  </code></pre>
  
  <p>And of course I could make it a function:</p>
  
  <pre><code>function PAnsicharToString(_a: PAnsiChar): string;
  begin
     // one of the above conversion codes goes here
  end;
  </code></pre>
  
  <p>All these options compile, but will they work? And what's the best practice here?</p>
  
  <p>Bonus points: The code should ideally compile and work with Delphi 2007 and newer versions as well.</p>