I need to process a set of bmp files using a console application, i'm using the TBitmap class, but the code doesn't compile because this error
E2003 Undeclared identifier: 'Create'
This sample app reproduces the issue
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Vcl.Graphics,
WinApi.Windows;
procedure CreateBitMap;
Var
Bmp : TBitmap;
Flag : DWORD;
begin
Bmp:=TBitmap.Create; //this line produce the error of compilation
try
//do something
finally
Bmp.Free;
end;
end;
begin
try
CreateBitMap;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
why this code doesn't compile?
The issue is in the order of your uses clause, the WinApi.Windows and Vcl.Graphics units have a type called TBitmap, when the compiler find an ambiguous type resolves the type using the last unit of the uses list where is present. in this case use the TBitmap of the Windows unit which points to the BITMAP WinAPi structure , to resolve this change the order of your units to
uses
System.SysUtils,
WinApi.Windows,
Vcl.Graphics;
or you can declare the type using the full qualified name like so
procedure CreateBitMap;
Var
Bmp : Vcl.Graphics.TBitmap;
Flag : DWORD;
begin
Bmp:=Vcl.Graphics.TBitmap.Create;
try
//do something
finally
Bmp.Free;
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With