Registriert seit: 27. Apr 2005
Ort: Görlitz
1.358 Beiträge
Delphi XE2 Professional
|
Re: Objecten ein gemeinsames Ereigniss zuweisen
28. Mai 2009, 11:45
Variante 1 wäre per RTTI:
Delphi-Quellcode:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, TypInfo;
type
TForm3 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormMouseEnter(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.FormCreate(Sender: TObject);
var
m : TMethod;
begin
m := GetMethodProp(Self, ' OnMouseEnter');
SetMethodProp(Button1, ' OnMouseEnter', m);
end;
procedure TForm3.FormMouseEnter(Sender: TObject);
begin
Caption := Sender.ClassName;
end;
end.
Variante 2 ist schmutzig, aber funktioniert:
Delphi-Quellcode:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm3 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormMouseEnter(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
TMyControl = class(TControl)
public
property OnMouseEnter;
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.FormCreate(Sender: TObject);
begin
TMyControl(Button1).OnMouseEnter := FormMouseEnter;
end;
procedure TForm3.FormMouseEnter(Sender: TObject);
begin
Caption := Sender.ClassName;
end;
end.
Benjamin Schwarze If I have seen further it is by standing on the shoulders of Giants. (Isaac Newton)
|
|
Zitat
|