HomeDelphiDelphi Error – W1044 Suspicious typecast of %s to %s

Delphi Error – W1044 Suspicious typecast of %s to %s

Delphi Compiler Error

W1044 Suspicious typecast of %s to %s

Reason for the Error & Solution

This warning flags typecasts like PAnsiChar(String) or PChar(AnsiString) which are casting between different string types without character conversion. If the code generating this warning calls a Win32 API routine, be sure that you use the wide version of the Win32 API routine when passing a String parameter:

var
  S: AnsiString;
begin
  MessageBox(0, PChar(S), 'Error', MB_OK);
end;

needs to be corrected to:

var
  S: AnsiString;
begin
  MessageBoxA(0, PAnsiChar(S), 'Error', MB_OK);
end;

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...