1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| 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
{ Déclarations privées }
public
{ Déclarations publiques }
// Déclaration de la méthode pour le OnClick
procedure ModifierCaption(Sender: TObject);
end;
var
Form1: TForm1;
btn: array[0..30,1..2] of TControl;
implementation
{$R *.dfm}
// Implémentation de la méthode
procedure TForm1.ModifierCaption(Sender: TObject);
begin
Form1.Caption:='Toto'; // On change le nom de la Form1 en toto
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
btn[1,2]:= Tbutton.Create(form1);
( btn[1,2] as Tbutton ).Parent:= form1;
( btn[1,2] as Tbutton ).Caption:= 'azeryuio';
( btn[1,2] as Tbutton ).Width:= 130;
( btn[1,2] as Tbutton ).Height:= 50;
( btn[1,2] as Tbutton ).Top:= 200;
( btn[1,2] as Tbutton ).Left:= 150;
// Redéfinition du OnClick du bouton
( btn[1,2] as Tbutton ).OnClick := Form1.ModifierCaption;
end;
end. |
Partager