您的位置:首页 > 编程语言 > Delphi

delphi 回调函数与函数指针

2015-08-21 12:15 323 查看
1.回调函数其实就是通过函数指针进行调用函数的,具体使用例子如下

       a)  定义回调函数类型  

type
THDFunction=function(k:integer;sExam:string):integer; stdcall;


         b)  回调函数的实现            

Function HdFunExample(k:integer;sExam:string):integer; stdcall;
Begin
if k=1226 then
ShowMessage(sExam);
End;
     

          c)  回调函数的调用

                  i)  定义调用回调函数的函数

function TForm1.DyHdFunExample(HdFun:THDFunction;I:Integer;str:string):boolean;
begin
HdFun(i,str);
end;
                  ii)调用回调函数             

procedure TForm1.btn7Click(Sender: TObject);
begin
DyHdFunExample(@HdFunExample,1226,'yes');
end;


  

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: