一个简单的类:
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

解决方案 »

  1.   

    你是做DLL吧给你看个确实可行的例子
    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; 这是动态调用
      

  2.   

    定义在dll里面的类当然不能直接引用。
    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.