源码如下:
program Project2;{$APPTYPE CONSOLE}uses
SysUtils,Dialogs;
type
tintpoint=^integer;
type
tcallback=procedure (i:tintpoint);
procedure callback(i:tintpoint);
begin
if i^=0 then
begin
showmessage('well');
end
else
begin
showmessage('bad') ;
end;
end;
procedure mycall(call:tcallback);
var
int:integer;
begin
callback(@int);end;
var
in1:integer;begin
readln(in1);
mycall(@in1);end.
也不知道这样是不是定义回调函数,还有就是程序老实输出bad,无法输出well,那里有错误请执教
program Project2;{$APPTYPE CONSOLE}uses
SysUtils,Dialogs;
type
tintpoint=^integer;
type
tcallback=procedure (i:tintpoint);
procedure callback(i:tintpoint);
begin
if i^=0 then
begin
showmessage('well');
end
else
begin
showmessage('bad') ;
end;
end;
procedure mycall(call:tcallback);
var
int:integer;
begin
callback(@int);end;
var
in1:integer;begin
readln(in1);
mycall(@in1);end.
也不知道这样是不是定义回调函数,还有就是程序老实输出bad,无法输出well,那里有错误请执教
tcallback = procedure (i: Integer); procedure callback(i: Integer);
begin
if i = 0 then
showmessage('well')
else
showmessage('bad');
end; procedure mycall(call: tcallback);
begin
call (Random(2)); //A回调C
end; begin
mycall(callback); //B调用A,并且告诉A回调函数C是哪一下
end.
假如说,主程序是UnitA,UnitA要调用B.dll,但B.dll也需要调用UnitA里面的过程ProcC,那么,UnitA就把这个ProcC的地址告诉B.dll,让B.dll通过这个地址去调用ProcC。这就是所谓的回调,即被调用方通过某种途径去调用这个调用方的某个过程。
这是我的理解