我在dialoge页面中有很多EditControls。它们被称为Edit1,Edit2等。是否可以像使用数组一样使用while循环从这些控件中获取值?我知道你可以做一个数组:
begin
// Loop 5 times
for i := 1 to (10 div 2) do
ShowMessage(Edit[i].Text); <- here I need to get value of Edit1, Edit2, et cetera
end;
如何使用字符串而不是数组?
答案 0 :(得分:1)
确保没有PS C:\Users\dskow\docker> docker run -d --name nano microsoft/nanoserver
Unable to find image 'microsoft/nanoserver:latest' locally
latest: Pulling from microsoft/nanoserver
bce2fbc256ea: Pull complete
4806a44e00a0: Pull complete
Digest: sha256:3331d7e40d93e8a3ea617450701a4f6550c699a673348b82fdc6fc01b9c44500
Status: Downloaded newer image for microsoft/nanoserver:latest
0d017c5adcbc5b04bb8f59c61a431bd5763c8792b97bc4fc400ffc48f0feab00
C:\Program Files\Docker\Docker\Resources\bin\docker.exe:
Error response from daemon:
container 0d017c5adcbc5b04bb8f59c61a431bd5763c8792b97bc4fc400ffc48f0feab00 encountered an
error during CreateContainer:
failure in a Windows system call:
The description string for parameter reference (%1) could not be found. (0x3ab6)
extra info:
{
"SystemType": "Container",
"Name": "0d017c5adcbc5b04bb8f59c61a431bd5763c8792b97bc4fc400ffc48f0feab00",
"Owner": "docker",
"IgnoreFlushesDuringBoot": true,
"LayerFolderPath": "C:\\ProgramData\\Docker\\windowsfilter\\0d017c5adcbc5b04bb8f59c61a431bd5763c8792b97bc4fc400ffc48f0feab00",
"Layers": [
{
"ID": "d3abf9e6-799a-5aa3-89a0-0f5fef546183",
"Path":"C:\\ProgramData\\Docker\\windowsfilter\\bc039df4c6ed43722c34bdf4ed7cc022b1b24c2f7edd8221dbb8d7645c2fdd10"},
{"ID": "4b849cd7-812a-5d2d-8b80-b0ca73856b43",
"Path": "C:\\ProgramData\\Docker\\windowsfilter\\8b68ab3315c2e26fe5c6fe5e616f0d13c502d421f7ca3d6160fddf008e29a02e"
}],
"HostName": "0d017c5adcbc",
"HvPartition": true,
"EndpointList": ["70d55b67-4127-4404-aae1-b3522ed89f1b"],
"HvRuntime": {
"ImagePath": "C:\\ProgramData\\Docker\\windowsfilter\\bc039df4c6ed43722c34bdf4ed7cc022b1b24c2f7edd8221dbb8d7645c2fdd10\\UtilityVM"
},
"AllowUnqualifiedDNSQuery": true
}.
PS C:\Users\dskow\docker>
,毕竟它是ComponentCount
属性。如果存在,请使用以下代码,并将名称TComponent
替换为Form1
的名称。
Object Parent of Edits
答案 1 :(得分:0)
如果您想要搜索表单中的所有TEdit,您可以执行以下操作:
var
i: Integer;
begin
for i := 0 to Self.ComponentCount- 1 do
if Self.Components[i] is TEdit then
ShowMessage(TEdit(Self.Components[i]).Text);
end;
如果您的TEdits放在其他控件(如GroupBox,Panel等)上,并且您想在这些控件内搜索,那么您应该这样做:
var
i: Integer;
begin
for i := 0 to gbx1.ControlCount - 1 do
if gbx1.Controls[i] is TEdit then
ShowMessage(TEdit(gbx1.Controls[i]).Text);
end;
或者你可以搜索多个TWinControls:
var
i: Integer;
begin
for i := 0 to Self.ControlCount - 1 do
begin
//TEdits are in TGroupBox
if Self.Controls[i] is TGroupBox then
ReadEdits(TGroupBox(Self.Controls[i]))
//TEdits are in TPanel
else if Self.Controls[i] is TPanel then
ReadEdits(TPanel(Self.Controls[i]))
else ... (other possible Parent Controls)
end
end;
procedure TForm1.ReadEdits(aParent: TWinControl);
var
i: Integer;
begin
for i := 0 to aParent.ControlCount - 1 do
if aParent.Controls[i] is TEdit then
ShowMessage(TEdit(aParent.Controls[i]).Text)
end;