ببینید دلفی یک زبان کامپایلری است پس اگر چیزی قرار جایی کار کنه باید از قبل تعریف شده باشه !
شما برای استفاده از رخداد یک کنترلی که با کد نویسی خواهید ساخت باید روال رخداد را از قبل تعریف کرده باشید .
type
Tfrm_main = class(TForm)
procedure FormCreate(Sender: TObject);
procedure ButtonTMPClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frm_main: Tfrm_main;
implementation
{$R *.dfm}
procedure Tfrm_main.FormCreate(Sender: TObject);
begin
with TButton.Create(Self) do begin
Parent := Self;
Width := 100;
Caption := 'Back to WHITE';
OnClick := ButtonTMPClick;
end;
end;
procedure Tfrm_main.ButtonTMPClick(Sender: TObject);
begin
//;
// Testing to change the color of the parent.
with TButton( Sender ) do begin
if Parent is TForm then
TForm( Parent ).Color := clWhite;
end;
end;
یا حق ...