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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic TEdit Creation 1

Status
Not open for further replies.

ThunderForest

IS-IT--Management
Mar 3, 2003
189
US
I can't seem to get these TEdits to display or created. What am I missing?

Code:
procedure TForm1.FormCreate(Sender: TObject);
var
x, y, tp, lft : integer;
begin
  y := 10;
  while (x <= y) do begin
      with (TEdit.create(self)) do begin
          Name := 'Edit'+intToStr(x);
          Text := '';
          Height := 17;
          Top := tp;
          left := lft;
          width := 80;
          tp := tp + 20;
      end;
      x := x + 1;
  end;
end;

Getting answers before I'm asked.
Providing answers if I can.
 
What happens if you initialise some of your variables such as
x
tp
lft

These can have random values in them so it is possible that the while clause is not being executed at all (because x may be greater than 10).

Andrew
Hampshire, UK
 
Also you need to tell Delphi who the parent of the TEdit is:
Code:
      with (TEdit.create(self)) do begin
          Name := 'Edit'+intToStr(x);
          [blue]Parent := self;[/blue]
          Text := '';
          Height := 17;
          ....

Andrew
Hampshire, UK
 
Sorry, I omitted most of them above. All the variables were initialzed in the original code.

x := 1;
y := 10;
tp := 146;
lft := 24;

Getting answers before I'm asked.
Providing answers if I can.
 
Thanks TowerBase. I knew I should have listened to my 'parents'. Parent was it.

Getting answers before I'm asked.
Providing answers if I can.
 
Setting the owner in the Create method merely tells the owner it is responsible for destroying the component when the owner is destroyed. The parent property is used for drawing. A TEdit inside a TGroupBox both have the same owner, but the GroupBox's parent is the form and the edit's parent is the groupbox.

GIS Programmer
City of Orem, UT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top