TBitmap.Create不能在delphi控制台应用程序中工作
发布时间:2020-12-15 04:29:09 所属栏目:大数据 来源:网络整理
导读:我需要使用控制台应用程序处理一组bmp文件,我正在使用TBitmap类,但代码不会编译,因为这个错误 E2003 Undeclared identifier: 'Create' 此示例应用程序会再现该问题 {$APPTYPE CONSOLE}{$R *.res}uses System.SysUtils,Vcl.Graphics,WinApi.Windows;procedure
我需要使用控制台应用程序处理一组bmp文件,我正在使用TBitmap类,但代码不会编译,因为这个错误
E2003 Undeclared identifier: 'Create' 此示例应用程序会再现该问题 {$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. 为什么这段代码不能编译? 解决方法
问题是按照你的uses子句的顺序,WinApi.Windows和Vcl.Graphics单元有一个名为TBitmap的类型,当编译器找到一个不明确的类型时,使用使用列表中存在的最后一个单元来解析类型.在这种情况下,请使用指向
BITMAP WinAPi结构的Windows单元的TBitmap,以将您的单位的顺序解决
uses System.SysUtils,WinApi.Windows,Vcl.Graphics; 或者您可以使用完全限定名称声明类型 procedure CreateBitMap; Var Bmp : Vcl.Graphics.TBitmap; Flag : DWORD; begin Bmp:=Vcl.Graphics.TBitmap.Create; try //do something finally Bmp.Free; end; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |