我的目的是:有加减两个按钮,点加(btn1)的时候实现加的功能,点减(btn2)的时候实现两个数相减的功能(不要改方法,我就想用回调函数试一下)unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
  type
    Tfunctiontype=function(a,b:Integer):Integer;type
  TForm1 = class(TForm)
    edt1: TEdit;
    edt2: TEdit;
    lbl1: TLabel;
    lbl2: TLabel;
    lbl3: TLabel;
    edt3: TEdit;
    btn1: TButton;
    btn2: TButton;
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function ADD(ParaA,ParaB:Integer):Integer;stdcall;
    function SUB(ParaA,ParaB:integer):Integer;stdcall;
    function Cal(a, b: Integer; fun:Tfunctiontype ): Integer;//stdcall;
  end;var
  Form1: TForm1;implementation
{$R *.dfm}{ TForm1 }function TForm1.ADD(ParaA, ParaB: Integer): Integer;
begin
  Result:=ParaA+ParaB;
end;function TForm1.SUB(ParaA, ParaB: integer): Integer;
begin
  result:=ParaA-ParaB;
end;function TForm1.Cal(a, b: Integer; fun:Tfunctiontype ): Integer;
begin
  result:=fun(a,b);
end;procedure TForm1.btn1Click(Sender: TObject);
begin
  edt3.Text:=IntToStr(Cal(StrToInt(edt1.Text),StrToInt(edt2.Text),ADD);
end;procedure TForm1.btn2Click(Sender: TObject);
begin
 edt3.Text:=IntToStr(Cal(StrToInt(edt1.Text),StrToInt(edt2.Text),SUB);
end;end.

解决方案 »

  1.   

    你把Add,Sub放到类里面,那函数就该这么定义
    Tfunctiontype=function(a,b:Integer):Integer of object;
      

  2.   

    function ADD(ParaA,ParaB:Integer):Integer;stdcall;
    还有,stdcall也和定义的函数不匹配,要么都有,要么都没有
      

  3.   

    错了... 1.声明: type Tfunctiontype=function(a,b:Integer):Integer; stdcall;
    2.public下面的函数删掉
    3.ADD,SUB,Cal前面的TForm1删掉
    4.调用:Cal(1,2,@ADD) 或者 Cal(1,2,@SUB); 前面2个参数自己定
      

  4.   

    补充一下
    5.ADD和SUB后面加上stdcall;另外也可以用of object这种对象形式,那么这样改:
    1.声明:type Tfunctiontype=function(a,b:Integer):Integer of object stdcall;
    2.public下面的函数ADD和SUB用了stdcall,后面实现的代码也要加上
    3.最后调用少了个括号