gpt4 book ai didi

memory-management - Lazarus Pascal - 如何在运行时删除按钮

转载 作者:行者123 更新时间:2023-12-02 05:26:12 24 4
gpt4 key购买 nike

我正在像这样在表单上动态创建命令按钮:

procedure TForm1.cmdAddClick(Sender: TObject);

var MenuButton : TButton;

begin MenuButton := TButton.Create(self);

ButtonCount:=ButtonCount + 1;

用 MenuButton 做

 begin
Top:= 10 + Height * ButtonCount;

Left := 10;
Parent := Panel1; //Parent container for the buttons.
OnClick := @YouClicked;
Caption := 'Menu item ' + IntToStr(ButtonCount);

end;

end;

运行上面几行几次后,我有很多按钮。

但是如何删除特定按钮?

我试过了

FreeAndNil (TButton(Sender));

但是好像不行...

最佳答案

按钮也必须从层次结构中移除。由 TForm.RemoveComponent 完成的 IIRC?

关于memory-management - Lazarus Pascal - 如何在运行时删除按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13062181/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com