Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to dinamically create array of tedit

Status
Not open for further replies.

sasogr

Programmer
Nov 6, 2003
3
MK
Example: I would like that on the event onbuttonclick edit1 is created, after the second click edit2 is created and so on...
 
How about something like this? This procedure places the Edit boxes in a vertical column. Variations might include a different layout or a limit to the number of boxes that can be created.
Code:
procedure Form.ButtonClick(Sender: TObject);
const
Code:
  // tailor these constants to suit your need
Code:
  FirstBoxTop = 10;
  BoxLeft = 10;
  BoxWidth = 121;
  SpaceBetweenBoxes = 4;
var
  I: Integer;
begin
Code:
  // find what boxes already exist named EditX
  // where X is a sequential number from 1..N
Code:
  I := 1;
  while FindComponent('Edit'+IntToStr(I))<>nil do
    Inc(I);
Code:
  // create an Edit button with next number I
  // and initialize properties
Code:
  with TEdit.Create(Self) do begin
    Parent := Self;
    Name := 'Edit' + IntToStr(I);
    Text := '';
    Left := BoxLeft;
    Width := BoxWidth;
    Top := FirstBoxTop + 
          (Height * (I-1)) + 
          (SpaceBetweenBoxes * (I-1));
  end;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top