Не могу понять как можно реализовать?
По клику на кнопку открывается программно созданная форма F1, на ней несколько программно созданных кнопок(B1,B2,B3).ъ
При щелчке на кнопку B1 создается программно форма F2 на ней тоже одна кнопка B4.
как присвоить этой(последней) кнопке событие, в котором будет закрываться форма F2. Проблема у меня в том, как мне кажется, что событие не видит программно созданную последнюю форму. Может я совсем не так реализую задачу
Код:
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | type BitButtonClass = class
class procedure BitClick(Sender : TObject);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var Forma : TForm;
BitButton1 : TBitBtn;
BitButton2 : TBitBtn;
BitButton3 : TBitBtn;
begin
Forma := TForm.Create(Self);
With Forma do
begin
Left := 100;
Top := 100;
Height := 300;
Width := 300;
BorderStyle := bsDialog;
end;
BitButton1 := TBitBtn.Create(Forma);
With BitButton1 do
begin
Parent := Forma;
Left := 20;
Top := 235;
Height := 25;
Width := 75;
Caption :='Добавить';
Name := 'BitButton1';
Visible := true;
OnClick := BitButtonClass.BitClick;
end;
BitButton2 := TBitBtn.Create(Forma);
With BitButton2 do
begin
Parent := Forma;
Left := 110;
Top := 235;
Height := 25;
Width := 75;
Caption :='Изменить';
Name := 'BitButton2';
Visible := true;
OnClick := BitButtonClass.BitClick;
end;
BitButton3 := TBitBtn.Create(Forma);
With BitButton3 do
begin
Parent := Forma;
Left := 200;
Top := 235;
Height := 25;
Width := 75;
Caption :='Удалить';
Name := 'BitButton3';
Visible := true;
OnClick := BitButtonClass.BitClick;
end;
Forma.ShowModal;
Forma.Free;
end;
class procedure BitButtonClass.BitClick(Sender: TObject);
var F: TForm;
BitButton4: TBitBtn;
begin
if TBitBtn(Sender).Name = 'BitButton1' then
begin
F := TForm.Create(nil);
With F do
begin
Left := 100;
Top := 100;
Height := 300;
Width := 300;
BorderStyle := bsDialog;
end;
BitButton4 := TBitBtn.Create(F);
With BitButton4 do
begin
Parent := F;
Left := 20;
Top := 135;
Height := 25;
Width := 75;
Caption :='Добавить';
Name := 'BitButton4';
Visible := true;
OnClick := BitButtonClass.BitClick;
end;
F.ShowModal;
exit;
end;
if (Sender as TBitBtn).Name = 'BitButton2' then
begin
ShowMessage('2');
end;
if (Sender as TBitBtn).Name = 'BitButton4' then
begin
F.Close;
ShowMessage('4');
exit;
end;
ShowMessage(TBitBtn(Sender).Name);
end;
|
То есть я пытаюсь в обработчике события создать новую форму с кнопкой и обработать её событие программно, чтоб закрыть форму.
Код:
1 2 3 4 5 6 | if (Sender as TBitBtn).Name = 'BitButton4' then
begin
F.Close;
ShowMessage('4');
exit;
end;
|
Пожалуйста подскажите.