【发布时间】:2023-03-31 23:03:01
【问题描述】:
我在 OnShow 事件中使用此代码在我的表单上创建了一个元素:
procedure TForm4.FormShow(Sender: TObject);
var
VertScrollLink:TVertScrollBox;
begin
VertScrollLink := TVertScrollBox.Create(form4);
VertScrollLink.Align := TAlignLayout.Client;
VertScrollLink.Parent := form4;
end;
在某些操作中,我需要动态删除布局:
for LIndex := form4.ComponentCount-1 downto 0 do
begin
if (form4.Components[LIndex].ToString='TVertScrollBox') then
begin
//showmessage(form4.Components[LIndex].ToString);
form4.Components[LIndex].Free;
end;
end;
此代码在 Windows 上运行良好,但在 Android 上不会删除任何内容。
【问题讨论】:
-
ARC 正在燃烧你。值得一读。 ToString 是一种测试类型的奇怪方法。这不是 PHP。使用
is运算符。您没有使用 XE。我删除了那个标签。 -
@DavidHeffernan 是的,我也使用 PHP :) 我将
if (form4.Components[LIndex].ToString='TVertScrollBox') then更改为if (form4.Components[LIndex] is TVertScrollBox) then,但没有任何改变!!问题似乎在form4.Components[LIndex].Free;!!! -
是的,我知道。 ARC是伤害你的东西。这就是我所说的。为什么你会期望 Free 在 ARC 上做任何事情。你了解 ARC。
标签: delphi firemonkey delphi-xe7 delphi-10-seattle delphi-10.1-berlin