高手请帮忙(100分)

  • 主题发起人 fsmchinese
  • 开始时间
F

fsmchinese

Unregistered / Unconfirmed
GUEST, unregistred user!
有两个类,如何把一个类的方法赋值给另一个类的方法?

方法的头如下:
TFFImageDraw = procedure(X,Y:Integer;aColor:TColor);

不知道有没有错!
 
procedure pp(var targetMethod;var sourcemethod);
var tmethod:pointer absolute targetmethod;
smethod:pointer absolute sourcemethod;
begin
tmethod:=smethod;
end;

就可以了.

不过在析构的时候不知道会有什么后果... ^_^
 
类的方法赋值不是象你说的

tclass1
procedure pro(x:integer);

procedure class1.pro(x:integer);


tclass2
procedure pro(x:integer);

tcalss2.pro := class1.pro;
 
unit Unit3;
interface
type
TProg = procedure(S:String) of object;

TA = Class
Prog :Tprog;
procedure ABC;
end;

implementation

procedure TA.ABC;
begin
Prog('12345');
end


end.
//-----------------------------------------------------------------------
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type

TForm2= class(TForm)
private
{ Private declarations }
public
{ Public declarations }
procedure Other(S:String);
end;

var
Form2: TForm2;

implementation

{$R *.DFM}

procedure TForm2.Other(S:String);
begin
Form2.Canvas.TextOut(10,10,S);
Showmessage(S);;
end;

end.
//-------------------------------------------------------------
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Unit2, Unit3, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
A :TA;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation



{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
A := TA.Create;
A.Prog := Form2.Other;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.show;
A.ABC;
end;

end.

 
多人接受答案了。
 

Similar threads

回复
0
查看
653
不得闲
回复
0
查看
679
不得闲
回复
0
查看
855
不得闲
回复
0
查看
666
不得闲
顶部