完整代码如下所示,定义了一个函数指针类型TFunctiontest = function (const a:integer; const b:integer; const c:integer): integer; 然后定义了一个指针变量。再定义了一个函数function functiona(const a :integer; const b:integer;const c:integer):integer;并将该函数的地址赋值给函数指针,然后通过函数指针去调用,希望得到的结果是1,2,3,但是没有得到第一个参数,求解答?
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TFunctiontest = function (const a:integer; const b:integer; const c:integer): integer;
var
Form1: TForm1;
implementation
{$R *.dfm}
function functiona(const a :integer; const b:integer;const c:integer):integer;
begin
showmessage(inttostr(a));
showmessage(inttostr(b));
showmessage(inttostr(c));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
pf : TFunctiontest;
const a:integer =1;
const b:integer =2;
const c:integer =3;
begin
pf := @functiona;
pf(a,b,c);
end;
end.