Create Tedit Array at Runtime;

Asked

Viewed 701 times

5

With the following code, I create an X amount 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 the following: I need to take the values of each created Dit, and receive it in a variable to be used later. How can I do this?

  • Receive in a variable? Wouldn’t it be better to create an array to store since there are several Edits. Unless you perform some type of run-time operation including and using only one variable.

  • Yes, I ended up thinking better my idea was the following: add the Edit in another vector, and then assign to a variable. Because I have to use these values that will be written in Edit created at runtime on a Tmemo.

  • And already implemented? It worked?

  • 1

    It worked, thank you.

  • If you want you can put the answer here in your own question so that everyone knows what you have done, your question has had 3 positive votes so far may be helping someone (;

2 answers

2


The values for some variables were added, according to the necessary index. Very simple, but in my case it was this.

   res := ArrayEdit[1].text;
   res2 := ArrayEdit[2].Text;
   res3 := ArrayEdit[3].text;

2

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.