一个简单的类:
function add(x,y:integer):integer;stdcall;
begin
result:=x+y;
end;
function mult(x,y:integer):integer;stdcall;
begin
result:=x*y;
end;
type
tcomp=class
public
function max(x,y:integer):integer;virtual;abstract;
function min(x,y:integer):integer;virtual;abstract;
end;
type
tcomp1=class(tcomp)
public
function max(x,y:integer):integer;override;
function min(x,y:integer):integer;override;
end ;
{tcomp1}
function tcomp1.max(x,y:integer):integer;
begin
if x>y then
result:=x
else
result:=y
end;
function tcomp1.min(x,y:integer):integer;
begin
if x<y then
result:=x
else
result:=y
end;
function createcomp1:tcomp1;stdcall;
begin
result:=tcomp1.Create ;
end;
exports
add,mult,createcomp1;如何引用这个类啊,下面的不行,该如何引用啊?
unit Unit2;interface
procedure createcomp1:tcomp1;
stdcall;external 'Project1.dll'; name 'createcomp1';
function add(x,y:integer):integer;
stdcall;external 'Project1.dll' name 'add';
function mult(x,y:integer):integer;
stdcall;external 'Project1.dll' name 'add';
type
tcomp=class
public
function max(x,y:integer):integer;virtual;abstract;
function min(x,y:integer):integer;virtual;abstract;
end;implementation
function add(x,y:integer):integer;stdcall;
begin
result:=x+y;
end;
function mult(x,y:integer):integer;stdcall;
begin
result:=x*y;
end;
type
tcomp=class
public
function max(x,y:integer):integer;virtual;abstract;
function min(x,y:integer):integer;virtual;abstract;
end;
type
tcomp1=class(tcomp)
public
function max(x,y:integer):integer;override;
function min(x,y:integer):integer;override;
end ;
{tcomp1}
function tcomp1.max(x,y:integer):integer;
begin
if x>y then
result:=x
else
result:=y
end;
function tcomp1.min(x,y:integer):integer;
begin
if x<y then
result:=x
else
result:=y
end;
function createcomp1:tcomp1;stdcall;
begin
result:=tcomp1.Create ;
end;
exports
add,mult,createcomp1;如何引用这个类啊,下面的不行,该如何引用啊?
unit Unit2;interface
procedure createcomp1:tcomp1;
stdcall;external 'Project1.dll'; name 'createcomp1';
function add(x,y:integer):integer;
stdcall;external 'Project1.dll' name 'add';
function mult(x,y:integer):integer;
stdcall;external 'Project1.dll' name 'add';
type
tcomp=class
public
function max(x,y:integer):integer;virtual;abstract;
function min(x,y:integer):integer;virtual;abstract;
end;implementation
解决方案 »
- 菜鸟询问cannot assign a TMemoStrings to TStringfield
- 小问题请教
- 文件传输的网上的一段代码???
- 为什么Delphi把38347转成日期为2004-12-26,而SQL Server却把它转成了2004-12-28,急!!
- 求救!!!
- 简单问题!fastreport中和adoquery连接的问题!
- 请问如何在stringgrid中输入数据
- 非常非常菜鸟的问题
- 上海合租住房!请版主先别删!
- 请教各位大侠:我用TNMStrm控件发送数据时,怎样实现定时连续发送?我现在发送一次成功,紧接着第二次发送就不行了,出现蓝屏.
- 如何让excelworksheet.cell.item['A1','A1']的文本内容自动换行?
- 局域网络上主机、备机切换如何实现
unit MaxMin;
interface
function Min1(x,y,z:Integer):Integer; stdcall;
function Max1(x,y,z:Integer):Integer; stdcall;
implementation
function Min1;external 'MaxMin.DLL' name 'Min1';
function Max1;external Max'Min.DLL' name 'Max1';
end.
这是静态调用
procedure TTestVcDLLForm.btnRunClick(Sender: TObject);
var
Handle:THandle;
Min1:TMin1;
Max1:TMax1;
begin
Handle:=LoadLibrary('MaxMin.dll'); //将“MaxMin.dll”的文件映象映射进调用进程的地址空间
if Handle<>0 then
begin
@Min1:=GetProcAddress(Handle,'Min1'); //取得DLL中函数Min1( )的地址
@Max1:=GetProcAddress(Handle,'Max1'); //取得DLL中函数Max1( )的地址
if (@Min1<>nil) and (@Min1<>nil) then
begin
edtMin.Text:=IntToStr(Min1(StrToInt(edtInt1.Text),
StrToInt(edtInt2.Text),StrToInt(edtInt3.Text))); //调用动态链接库中的函数Min1
edtMax.Text:=IntToStr(Max1(StrToInt(edtInt1.Text),
StrToInt(edtInt2.Text),StrToInt(edtInt3.Text))); //调用动态链接库中的函数Max1
end else ShowMessage('调用函数“GetProcAddress”时出错!');
FreeLibrary(Handle); //从进程的地址空间中解除“MaxMin.dll”文件的映射
end;
end; 这是动态调用
unit Unit2;interfacetype
tcomp=class //定义基类
public
function max(x,y:integer):integer;virtual;abstract;//必须是抽象和虚拟类型
function min(x,y:integer):integer;virtual;abstract;
end;type
tcomp1=class(tcomp)//重新定义
end;function createcomp1:tcomp1;
stdcall;external 'Project1.dll' name 'createcomp1';
function add(x,y:integer):integer;
stdcall;external 'Project1.dll' name 'add';
function mult(x,y:integer):integer;
stdcall;external 'Project1.dll' name 'mult';implementationend.