![]() |
专题推荐:
Mysql初级教程 |
MySQL数据库技术强化学习 |
nginx负载平衡 |
搜索引擎优化(SEO) |
Linux命令详解 |
Linux网管 |
常用手册: MySQL4.1中文手册 | HTML4.0参考手册 | APACHE 2.0中文在线手册 | MySQL 5.1参考手册 | FreeBSD 7.0使用手册 |
library SampleDLL;
uses
SysUtils, Classes, Sample;
TYPE
TTempcomp = class(TComponent)
private
public
constructor Create1;
published
end;
var
Sample1 :Sample;
SaveExit :Pointer;
temp1 :TTempcomp;
constructor TTempcomp.Create1;
begin
// inherited Create(self);
end;
/==============================================
function OpenSample: Boolean; stdcall; export;
begin
HwCtrl:= Sample1.Create(temp1);
If Sample1.Actived then result:=true;
end;
procedure CloseSample; stdcall; export;
begin
Sample1.Destroy;
end;
function Actived: Boolean; stdcall; export;
begin
result:=Sample1.Actived;
end;
function Pro1: Interger; stdcall; export;
begin
result:= Sample1.Pro1;
end;
function Pro2: Interger; stdcall; export;
begin
result:= Sample1.Pro2;
end;
/==============================================
procedure libexit; far
begin
if Sample1.Actived =true then
Sample1.Destroy;
ExitProc:=SaveExit;
temp1.Destroy;
end;
exports
OpenSample,CloseSample,Actived ,Pro1,Pro2;
begin
temp1:=TTempcomp.Create1;
SaveExit:=ExitProc;
ExitProc:=@libexit;
end.
解释:
因为VCL控件都继承于TComponent,TComponent的构造函数需要一个AOwner并且也是TComponent,VCL控件的Create、Destroy都由控件的拥有者来动作,也就是AOwner;所以我在此DLL中新设置了一个TTempcomp类继承于Tcomponent且性设置了一个constructor(构造函数)Create1,而实际构造时什么都不做,以次作为要Create的Aowner;其他还有一种办法就是用Application作为Aowner但是它是基于Tform的作出来的DLL太大;其实,Inprise(原Borland)尽可以象MicroSoft一样用一些象DCOM类似的组件形式使得产品在同一产品时代保持一定的互用性,来增加产品群的生命力.