如题Delphi Dll中回调的使用。先感谢下!着急在线等!

解决方案 »

  1.   

    DELPHI中回调函数的使用
      

  2.   

    主要是dll部分能给出代码吗。谢谢了
      

  3.   

    library   Project1;  
       
       
      uses  
          SysUtils,  
          Classes;  
       
       
      type  
        TCallBackProc   =   procedure(vi:   PChar);  
       
        procedure   Test(vs:   PChar;   cbp:   TCallBackProc);   stdcall;  
        begin  
            TCallBackProc(cbp)(vs);  
        end;  
       
      {$R   *.res}  
       
      exports  
          Test;  
       
      begin  
      end.
      

  4.   

    谢谢了。是在不想在问了。说实话问的真闹心。谢了"hongqi162 "
      

  5.   


    //月亮老大发的链接不是很清楚了吗,还讲什么?
    //你是想在dll中回调主调的函数???
    //回调即把函数名A当作另一个函数B的参数使用
    //有几个步骤:
    //1.声明函数类型
    //2.创建相应的函数体
    //3.创建函数变量
    //4.把函数名赋给变量(就是把函数指针赋给刚刚创建的函数变量)
    //5.把这个变量放到B的参数中
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TFuncType = procedure (Msg: string) of Object;//声明类型  TForm1 = class(TForm)
        btn1: TButton;
        procedure btn1Click(Sender: TObject);
      private
        { Private declarations }
        procedure MyTestFunc(Msg: string) ;//创建与类型相同的函数    procedure CallbackFunc(F: TFuncType) ;//回调
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.MyTestFunc(Msg: string) ;
    begin
       ShowMessage(Msg);
    end;
    procedure TForm1.CallbackFunc(F: TFuncType);
    begin
       F('ok');
    end;procedure TForm1.btn1Click(Sender: TObject);
    var
      testFunc: TFuncType;
    begin
      testFunc:=MyTestFunc ;
      CallbackFunc(testFunc);
    end;end.