tpanel.Create(self).Name := 'panel1' ;
with tpanel(FindComponent('page1')) do
begin
Left := 50;
Top := 50;
width := 100;
height := 100;
Parent := form1;
end;
//上面时第一次创建的,成功了//接着我如下创建
TEdit.Create(self).Name := 'test';
with TEdit(FindComponent('test')) do
begin
Left := 100;
Top := 100;
width := 100;
height := 100;
parent:= tpanel(form1.FindComponent('page1' ));
end;
结果不成功,但是如果把最后parent := form1就可以了,如果我想把他添加到page1的tpanel上应该怎么办啊
with tpanel(FindComponent('page1')) do
begin
Left := 50;
Top := 50;
width := 100;
height := 100;
Parent := form1;
end;
//上面时第一次创建的,成功了//接着我如下创建
TEdit.Create(self).Name := 'test';
with TEdit(FindComponent('test')) do
begin
Left := 100;
Top := 100;
width := 100;
height := 100;
parent:= tpanel(form1.FindComponent('page1' ));
end;
结果不成功,但是如果把最后parent := form1就可以了,如果我想把他添加到page1的tpanel上应该怎么办啊
tpanel.Create(self).Name := 'panel1' ;
with tpanel(FindComponent('page1')) do上面是'panel1' 下面是page1 怎么会成功呢?? tpanel.Create(self).Name := 'panel1' ;
with tpanel(FindComponent('panel1')) do
begin
Left := 50;
Top := 50;
width := 100;
height := 100;
Parent := form1;
caption:='newpanel';
end; TEdit.Create(self).Name := 'test';
with TEdit(FindComponent('test')) do
begin
Left := 0;
Top := 0;
width := 100;
height := 100;
parent:= tpanel(form1.FindComponent('panel1' ));
end;
procedure TForm1.FormCreate(Sender: TObject);
var
p:TPanel;
E:TEdit;
begin
p:=Tpanel.Create(self);
with p do begin
name:='Panel1';
Left := 50;
Top := 50;
width := 300;
height := 300;
Parent := form1;
end;
E:=TEdit.Create(self);
with E do begin
name:='edit1';
Left := 100;
Top := 100;
width := 100;
height := 100;
parent:= p;
end;
end;
to sailxia(小帆) 有没有前面先不定义变量也能实现的方法,第一个panel也没有定义panel变量动态生成了,第二个为什么不行呢?
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
tpanel.Create(self).Name := 'panelX' ;
with tpanel(FindComponent('panelX')) do
begin
Left := 50;
Top := 50;
width := 100;
height := 100;
Parent := form1;
caption:='panelX';
end; TEdit.Create(self).Name := 'testX';
with TEdit(FindComponent('testX')) do
begin
Left := 0;
Top := 0;
width := 100;
height := 100;
parent:= tpanel(form1.FindComponent('panelX' ));
end;end;end.
//=====如果还是有问题,应该可能的问题是和已存在的组件名字有冲突?