I have a lot of EditControls in a dialoge page. They are called Edit1, Edit2, et cetera. Is it possible to get the values from those controls using a while loop like you could with an array? I know for an array you could do something like:
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;
How to do this with strings instead of arrays?
Make sure that there is no ComponentCount
, after all it is a TComponent
property. If it exists, use this code below and replace the name Form1
with the name of your Object Parent of Edits
.
procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
begin
for i := 0 to Form1.ComponentCount -1 do
if Form1.Components[i].Name = 'Edit' + IntToStr(i+1) then
TEdit(Form1.Components[i]).Text := 'NewTextEdit' + IntToStr(i+1);
end;