由于好几个EXE都有ABOUT窗体。就想把ABOUT做成DLL然后给EXE调用。建立了一个ABOUT.DLL,工程文件代码如下
library About;uses
SysUtils,
Classes,
AboutFrm in 'AboutFrm.pas' {FormAbout},
PubUnit in 'PubUnit.pas';{$R *.res}exports
ShowAboutFrm;beginend.
AboutFrm是窗体,其中没有加任何代码PubUnit是自己加的一个UNIT,代码如下unit PubUnit;interface
Uses Forms;procedure ShowAboutFrm(AHandle: THandle; ACaption: String);stdcall;implementation
Uses AboutFrm;procedure ShowAboutFrm(AHandle: THandle; ACaption: String);
var
AboutFrm: TFormAbout;
begin
Application.Handle := AHandle;
AboutFrm := TFormAbout.Create(Application); //创建并显示窗体
try
AboutFrm.Caption :=ACaption;
AboutFrm.ShowModal; //显示方式为模式化
finally
AboutFrm.Free; //用完后卸载该窗体
end;
end;
end.
程序调用的地方是这么写的
var
OneHandle:THandle;
ShowAboutFrm:procedure(AHandle: THandle; ACaption: String);stdcall;
begin try
try
OneHandle:=LoadLibrary('About.Dll');
if OneHandle<>0 then
@ShowAboutFrm := GetProcAddress(OneHandle,'ShowAboutFrm');
if Not (@ShowAboutFrm<>nil) then
ShowAboutFrm(Application.Handle,'关于')
else
RaiseLastWin32Error;
except
On E:Exception do
ShowMSG(E.Message);
end;
finally
FreeLibrary(OneHandle);
end;
end;程序运行时总报 A call to an OS function failed谢谢
library About;uses
SysUtils,
Classes,
AboutFrm in 'AboutFrm.pas' {FormAbout},
PubUnit in 'PubUnit.pas';{$R *.res}exports
ShowAboutFrm;beginend.
AboutFrm是窗体,其中没有加任何代码PubUnit是自己加的一个UNIT,代码如下unit PubUnit;interface
Uses Forms;procedure ShowAboutFrm(AHandle: THandle; ACaption: String);stdcall;implementation
Uses AboutFrm;procedure ShowAboutFrm(AHandle: THandle; ACaption: String);
var
AboutFrm: TFormAbout;
begin
Application.Handle := AHandle;
AboutFrm := TFormAbout.Create(Application); //创建并显示窗体
try
AboutFrm.Caption :=ACaption;
AboutFrm.ShowModal; //显示方式为模式化
finally
AboutFrm.Free; //用完后卸载该窗体
end;
end;
end.
程序调用的地方是这么写的
var
OneHandle:THandle;
ShowAboutFrm:procedure(AHandle: THandle; ACaption: String);stdcall;
begin try
try
OneHandle:=LoadLibrary('About.Dll');
if OneHandle<>0 then
@ShowAboutFrm := GetProcAddress(OneHandle,'ShowAboutFrm');
if Not (@ShowAboutFrm<>nil) then
ShowAboutFrm(Application.Handle,'关于')
else
RaiseLastWin32Error;
except
On E:Exception do
ShowMSG(E.Message);
end;
finally
FreeLibrary(OneHandle);
end;
end;程序运行时总报 A call to an OS function failed谢谢
解决方案 »
- 如何让dbgrideh选中某行的时候,焦点行颜色不变?
- 如何实现选择文件夹(不是文件)的路径功能
- 哪位兄弟帮忙写个 从网络拷贝文件的程序。
- 在控制台下cmd如何给socket添加事件控制?
- 自编控件的string类型属性怎么实现默认值, Default 'abc'的就别进来了。
- delphi如何实现按一个按键就直接打开一个网页
- memo的设置问题!
- 抽烟对编程有好处吗?
- 为何我在Dataset中编写OnGetText,OnSetText可是,却不让我将改变数据写入库
- delphi创建dll给c++调用,dll里加入ADO控件查询数据库,报错
- 如何向dbgrid中连续添加多行以后,一起向数据库中保存?
- 一段sql语句,我执行like可以,执行<和>都无法返回数据
改為: ACaption: pchar;或者在代碼中修改如下:uses
ShareMem,
SysUtils,
Classes,
...兩邊都要加上這個 ShareMem
RaiseLastWin32Error;
except
On E:Exception do
ShowMSG(E.Message);
end;這部分代碼, 好象沒什麼用
ShowAboutFrm(Application.Handle,'关于')
else
RaiseLastWin32Error;