如题。
谢谢!!
谢谢!!
解决方案 »
- delphi实现Internet网上的文件传送
- 如何让用户自定义字段
- 各位老大:使用delphi如何实现COM组件的连接点
- 怎样通过HTTP代理下载FTP或者BT,玩游戏等?
- p2p打洞可以1对多么?
- 传输的问题,进来看看,先谢了
- 急问!!!编写delphi程序,怎样打开指定路径的文件。
- procedure CMMouseEnter(var msg:TMessage); message CM_MOUSEENTER;解释什么意思?谢谢
- 窗体释放的问题!
- 怎么实现像Windows底下的右击菜单里?+你的命令来启动程序的不同功能?(Delphi)
- 如何获取外部应用程序的句柄?
- Delphi计算字符串哈希码程序
就像 API 函数那样,可以把函数地址传递到 API 里去,然后 API 就会调用那个函数。
就是回调函数。我想自己定义一个这样的函数。
谢谢~~~
function Sum(var a,b,c:Integer)Integer;
begin
a:=1;
b:=2
c:=3
end;
procedure TForm1.Button1Click(Sender: TObject);
var a,b,c,d:Integer;begin
a:=0;
b:=0;
c:=0;
d:=Sum(a,b,c);
showmessage(intToStr(d));
end;
ID: [ 000111 ]
A call back function is a function which you write, but is called by some other
program or module, such as windows. To create a callback function, you must
first declare a function type, the funciton itself, and implement the function.In the interface section:{ In main program interface }
typeTCallBackFunction = function(s: string): integer; CallMe(s: string): integer; And in the Implementation section: { In main program implementation }
procedure TestCallBack(CallBackFunction: TCallBackFunction); far; external 'Other';
{ Note that 'other' is a Dll containing the procedure TestCallBack } function CallMe(s: PChar): integer;
begin{ what ever you need to do }
CallMe := 1;
{ What ever you need to return }end; procedure TForm1.Button1Click(Sender: TObject);
beginTestCallBack(CallMe);end; Note that in 'Other' you would also declare a function type, and use it like this:
{ in library Other interface }
typeTMainFunction = function(s: string): integer;
TestCallBack(MainFunc: TMainFunction);
{ in library Other implementation }
TestCallBack(MainFunc: TMainFunction);
varresult: integer;beginresult:=MainFunc('test');end;
或者CODE
TTest = function (a, b: Integer): Boolean;function Hello(a, b: Integer): Boolean;
begin
return a = b;
end;procedure Test(a: Integer; b: Integer; Func: TTest);
begin
if Func(a, b) then
ShowMessage('Equal')
else
ShowMessage('Not Equal')
end;
Test(1, 2, Hello);
楼主该结贴了
begin
end;procedure formshow;
begin
t:= ...
yourfun_name(t)
showmessage(t)
end;这里的t就是向你要求的那样可以传进去再传出来
那,再请问,我想导出这个有回调参数的函数呢?(DLL导出)
给其它语言使用,比如 VB.
谢谢~~~~~~
type
TTest = function (a, b: Integer): Boolean; stdcall;function Hello(a, b: Integer): Boolean; stdcall;
begin
return a = b;
end;To Linux2001:下次你要回答的题目跟我说一声,我不会和你抢分的。:P