Create TEdit Array at run time;

5

With the following code, I create an X quantity of edits:

var
  x : integer;
  var2: integer;
begin
  var2 := strtoint(edit2.Text);
  for x := 1 to var2 do
  begin
    ArrayEdit[x] := TEdit.Create(Self);
    ArrayEdit[x].Parent:= Self;
    ArrayEdit[x].Left := 83 + x * 50;
    ArrayEdit[x].Top := 130;
    ArrayEdit[x].Width := 41;
    ArrayEdit[x].Height :=24;
    ArrayEdit[x].Name := 'edit'+ inttostr(x+20);
    ArrayEdit[x].Text := '';
    ArrayEdit[x].ShowHint:=true;
    ArrayEdit[x].Hint:='edit'+ inttostr(x+20);
  end;
end;

My question is this: I need to get the values of each created edit, and receive in a variable to be used later. How can I do this?

    
asked by anonymous 21.09.2015 / 19:30

2 answers

2

Added values for some variables, according to the required index. Very simple, but for my case it was that.

   res := ArrayEdit[1].text;
   res2 := ArrayEdit[2].Text;
   res3 := ArrayEdit[3].text;
    
22.09.2015 / 16:21
2

Your ArrayEdit is an array of objects of type TEdit so you simply access it in the position that will have a TEdit, then just access the Text property of it.

 for x := 1 to length(ArrayEdit) do
  begin
    ArrayEdit[x].text
  end;
    
22.09.2015 / 16:25