如
private
FMyEvent: TNotifyEvent
public
MyEvent: TNotifyEvent read FMyEvent write FMyEvent
在你需要触发事件的地方调用以下代码:
if Assinged(FMyEvent)
FMyEvent(Self)
当然可以,还可以动态创建控件数组,给你两个简单的例子:动态创建组件:
procedure TForm1.Button1Click(Sender: TObject)
var
MyButton : TButton
begin
MyButton := TButton.Create(Self)
MyButton.Parent := Form1
MyButton.Top := 10
MyButton.Left := 10
MyButton.Height := 25
MyButton.Width := 75
MyButton.Caption := '确定'
MyButton.OnClick := Mybuttonclick
MyButton.Show
end
procedure TForm1.Mybuttonclick(Sender: TObject)
begin
Application.MessageBox('动态创建的Button组件','提示',64)
end
动态创建控件数组:
procedure TForm1.Button1Click(Sender: TObject)
var
MyButton:array of TButton
i,m:integer
begin
SetLength(MyButton,6)
for i := 0 to 5 do
begin
MyButton[i] := TButton.Create(Self)
MyButton[i].Top := 10 + i * 30
MyButton[i].Left :=20
MyButton[i].Height := 30
MyButton[i].Width := 70
MyButton[i].Parent := Self
MyButton[i].Caption := '按钮'
MyButton[i].OnClick := Mybuttonclick
MyButton[i].Show
Button1.Visible := False
end
end
procedure TForm1.Mybuttonclick(Sender: TObject)
begin
showmessage('动态组件数组')
end
上面都是动态创建button组件的例子,其他的组件你可以参照上面的例子自己写。。。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)