Всё передаётся, забыл свойство Name присвоить.
Код:
procedure TForm1.Button2Click(Sender: TObject);
var
MyForm : TForm;
Memo1 : TMemo;
BitButton1,
BitButton2,
BitButton3 : TButton;
begin
MyForm := TForm.Create(Self);
with MyForm do
begin
Left := 100;
Top := 100;
Height := 300; // Высота формы
Width := 300; // Ширина формы
BorderStyle := bsDialog;
Memo1 := TMemo.Create(MyForm);
with Memo1 do
begin
Parent := MyForm;
Left := 10;
Top := 10;
Height := 210; // Высота
Width := 270; // Ширина
Visible := True;
end;
BitButton1 := TButton.Create(MyForm);
with BitButton1 do
begin
Parent := MyForm;
Left := 20;
Top := 235;
Height := 25; // Высота
Width := 75; // Ширина
Caption := 'Добавить';
Name := 'BitButton1';
Visible := True;
OnClick := BitButtonClass.BitClick;
end;
BitButton2 := TButton.Create(MyForm);
with BitButton2 do
begin
Parent := MyForm;
Left := 100;
Top := 235;
Height := 25; // Высота
Width := 75; // Ширина
Caption := 'Удалить';
Name := 'BitButton2';
Visible := True;
OnClick := BitButtonClass.BitClick;
end;
BitButton3 := TButton.Create(MyForm);
with BitButton3 do
begin
Parent := MyForm;
Left := 180;
Top := 235;
Height := 25; // Высота
Width := 75; // Ширина
Caption := 'Отмена';
Name := 'BitButton3';
Visible := True;
OnClick := BitButtonClass.BitClick;
end;
end;
MyForm.ShowModal;
MyForm.Free;
end;
class procedure BitButtonClass.BitClick(Sender: TObject);
begin
if Sender is TButton then
begin
if (Sender as TButton).Name = 'BitButton1' then
ShowMessage('Кнопка 1')
else if (Sender as TButton).Name = 'BitButton2' then
ShowMessage('Кнопка 2')
else if (Sender as TButton).Name = 'BitButton3' then
ShowMessage('Кнопка 3');
end;
end;
Можно также не просто показать какая кнопка, но и реальные действия "навесить".
Код:
procedure TForm1.Button2Click(Sender: TObject);
...
Memo1 := TMemo.Create(MyForm);
with Memo1 do
begin
Parent := MyForm;
Left := 10;
Top := 10;
Height := 210; // Высота
Width := 270; // Ширина
Name := 'Memo1'; // добавим имя
Visible := True;
end;
...
end;
class procedure BitButtonClass.BitClick(Sender: TObject);
begin
if Sender is TButton then
begin
if (Sender as TButton).Name = 'BitButton1' then
TMemo(TForm((Sender as TButton).Parent).FindComponent('Memo1')).Lines.Add('Новая строка')
else if (Sender as TButton).Name = 'BitButton2' then
TMemo(TForm((Sender as TButton).Parent).FindComponent('Memo1')).Lines.Clear
else if (Sender as TButton).Name = 'BitButton3' then
TForm((Sender as TButton).Parent).Close;
end;
end;