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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
   |  
unit ex08a;
 
interface
 
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
  Generics.Collections;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    ScrollBox1: TScrollBox;
    procedure FormActivate(Sender: TObject);
    procedure aButtonClick(Sender: TObject);
  end;
 
var
  Form1: TForm1;
  Bprem: boolean = true;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.aButtonClick(Sender: TObject);
begin
  showmessage(TButton(Sender).Caption);
end;
 
procedure TForm1.FormActivate(Sender: TObject);
var
  Panel1: TPanel;
  i1, i2: integer;
  b1: boolean;
  Button1: TButton;
begin
  if not Bprem then
    exit;
  Bprem := false;
  for i1 := 0 to 7 do
  begin
    for i2 := 0 to 7 do
    begin
      Panel1 := TPanel.Create(self);
      Panel1.Parent := ScrollBox1;
      Panel1.Width := 100;
      Panel1.Height := 40;
      Panel1.BevelInner := bvRaised;
      Panel1.BevelOuter := bvnone;
      Panel1.left := i1 * 100;
      Panel1.top := i2 * 40;
      Panel1.ParentBackground := false;
      if i1 = 2 then
      begin
        Button1 := TButton.Create(self);
        Button1.Parent := Panel1;
        Button1.OnClick := aButtonClick;
        Button1.left := 10;
        Button1.top := 10;
        Button1.Width := 80;
        Button1.Height := 20;
        Button1.Caption := i2.ToString;
      end;
    end;
  end;
end;
 
end. | 
Partager