怎样在delphi 下定义回调函数(callback function)?(100分)

  • 主题发起人 主题发起人 kasa
  • 开始时间 开始时间
参照:<br><br>type<br>&nbsp; EnumWindowsProc = function (Hwnd: THandle;<br>&nbsp; &nbsp; Param: Pointer): Boolean; stdcall;<br><br>function GetTitle (Hwnd: THandle; Param: Pointer): Boolean; stdcall;<br>var<br>&nbsp; Text: string;<br>begin<br>&nbsp; SetLength (Text, 100);<br>&nbsp; GetWindowText (Hwnd, PChar (Text), 100);<br>&nbsp; FormCallBack.ListBox1.Items.Add (<br>&nbsp; &nbsp; IntToStr (Hwnd) + ': ' + Text);<br>&nbsp; Result := True;<br>end;<br><br>procedure TFormCallback.BtnTitlesClick(Sender: TObject);<br>var<br>&nbsp; EWProc: EnumWindowsProc;<br>begin<br>&nbsp; ListBox1.Items.Clear;<br>&nbsp; EWProc := GetTitle;<br>&nbsp; EnumWindows (@EWProc, 0);<br>end;
 
抄来的:<br>type<br>&nbsp; TCallBackFunction = function(s: string): integer;<br>&nbsp; CallMe(s: string): integer;<br><br><br><br>procedure TestCallBack(CallBackFunction: TCallBackFunction); far; external 'Other';<br>{ Note that 'other' is a Dll containing the procedure TestCallBack }<br><br>function CallMe(s: PChar): integer;<br>begin<br>&nbsp; { what ever you need to do }<br>&nbsp; CallMe := 1; { What ever you need to return }<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; TestCallBack(CallMe);<br>end;<br><br>type<br>&nbsp; TMainFunction = function(s: string): integer;<br>&nbsp; TestCallBack(MainFunc: TMainFunction);<br>{ in library Other implementation }<br>TestCallBack(MainFunc: TMainFunction);<br>var<br>&nbsp; result: integer;<br>begin<br>&nbsp; result:=MainFunc('test');<br>end;<br>
 
接受答案了.
 
后退
顶部