gpt4 book ai didi

delphi - Delphi从许多编辑中读取

转载 作者:行者123 更新时间:2023-12-03 19:04:10 26 4
gpt4 key购买 nike

是否可以更改以下内容:

myfunction(1,1,strtoint(form1.a11.text));
myfunction(1,2,strtoint(form1.a12.text));
myfunction(1,3,strtoint(form1.a13.text));
myfunction(1,4,strtoint(form1.a14.text));
myfunction(1,5,strtoint(form1.a15.text));
myfunction(1,6,strtoint(form1.a16.text));
myfunction(1,7,strtoint(form1.a17.text));
myfunction(1,8,strtoint(form1.a18.text));
myfunction(1,9,strtoint(form1.a19.text));

像这样?
   for i:=1 to 9 do
myfunction(1,i,strtoint(form1.'a1'+i.text));

我知道这行不通,但是我想找到一种方法来更快地做到这一点。相似的东西

最佳答案

您可以使用FindComponent通过名称查找组件。前提是组件归表单对象所有。这很有可能是一个有效的假设。

(form1.FindComponent('a1'+IntToStr(i)) as TEdit).Text


我个人不喜欢这种代码。我将创建一个编辑控件数组:

type
TForm1 = class
....
private
FEditArr: array [1..9] of TEdit;
....


然后在构造函数中,我将初始化数组:

FEditArr[1] := a11;
FEditArr[2] := a12;
....


这使得随后获得给定索引的编辑控件的代码更加整洁。

如果沿着这条路线走,那么可能也很容易在运行时创建编辑控件,而不是必须在设计器中全部创建它们,然后在构造函数中编写该数组分配代码。概述中,它看起来像这样。

for i := 1 to 9 do
begin
FEditArr[i] := TEdit.Create(Self);
FEditArr[i].Parent := Self;
FEditArr[i].Left := ...;
FEditArr[i].Top := ...;
end;

关于delphi - Delphi从许多编辑中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15176395/

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