unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TestClass = class
public
procedure Test(X: Integer)
overload
//类中的方法
procedure Test(X, Y: Integer)
overload
//类中的方法
end;
FuncPointer1 = procedure(X: Integer) of object
//指针是方法指针
FuncPointer2 = procedure(X, Y: Integer) of object
//指针是方法指针
procedure FuncAssign(FP1: FuncPointer1)
overload;
procedure FuncAssign(FP1: FuncPointer2)
overload;
var
TestClass1:TestClass;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure FuncAssign(FP1: FuncPointer1)
overload;
begin
FP1(1);
end;
procedure FuncAssign(FP1: FuncPointer2)
overload;
begin
FP1(1, 2);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
FP1: FuncPointer1;
FP2: FuncPointer2;
begin
TestClass1 := TestClass.Create;
FP1 := TestClass1.Test;
FP2 := TestClass1.Test;
FuncAssign(FP1);
FuncAssign(FP2);
TestClass1.Free;
end;
{ TestClass }
procedure TestClass.Test(X: Integer);
begin
ShowMEssage('X');
end;
procedure TestClass.Test(X, Y: Integer);
begin
ShowMEssage('X, Y');
end;
end.