Recent

Author Topic: Why can't Lazarus detect that I'm using Wide version of Windows.CreateFile?  (Read 4198 times)

EMBarbosa

  • New Member
  • *
  • Posts: 15
Trying to compile a new application, I'm receiving this Error: Incompatible type for arg no. 1: Got "PWideChar", expected "PChar"
In this line:
Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
var
  hFile: Thandle;
begin
  {$DEFINE UNICODE}
     hFile := Windows.CreateFile( PWideChar('\.\\c:\test.txt'),
               GENERIC_READ or GENERIC_WRITE,
               FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING,
               FILE_ATTRIBUTE_NORMAL  or FILE_FLAG_WRITE_THROUGH or FILE_FLAG_NO_BUFFERING, 0);
end

But I see that unidef.inc used by Windows.pas define the function, but is ascdef.inc version that appears in code completion.
Anyway, if I use Windows.CreateFileW instead, the error disappear.
Just wanted to know why.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11458
  • FPC developer.
In Pascal, preprocessor state does NOT flow from module to module.

So the "UNICODE" that you define is local to the unit only (from the place where you define it till the end of the file). Windows is precompiled with ansi, and is stored in the FPC "units" dir, and can only be changed by recompile the whole of FPC.


The reason for this behaviour is that the bond between compilation units in (unit based) Pascal is stronger, and the compiler checks both ends.

 

TinyPortal © 2005-2018