unit uMarkScore;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, RzPanel, StdCtrls, RzEdit;type
TfrmMarkScore = class(TForm)
private
LblArray : Array[1..100] of TLabel;
edtArray : Array[1..100] of TEdit;
public
iMainid:integer;
end;var
frmMarkScore: TfrmMarkScore;implementation
uses uDataModule;{$R *.dfm}{ TfrmMarkScore }procedure TfrmMarkScore.CreateComponent;
var
i: integer;
begin
for i := 0 to dataBase.adoDtCreate.RecordCount - 1 do
begin
LblArray[i] := TLabel.Create(nil);
LblArray[i].Name := 'lbl'+IntToStr(i);
LblArray[i].Caption := dataBase.adoDtCreate.Fields[0].AsString+':';
LblArray[i].Left := 48;
LblArray[i].Top := 24+i*64;
LblArray[i].Visible := true;
LblArray[i].Show; EdtArray[i] := Tedit.Create(nil);
EdtArray[i].Name := 'edt'+IntToStr(i);
EdtArray[i].Left := 48;
EdtArray[i].Top := 48+i*64;
EdtArray[i].Visible := true;
EdtArray[i].OnKeyPress := OnkeyPress;
EdtArray[i].Show;
end;
end;以上是代码,但showmodal, 界面出来了,但创建的控件就是看不到,求高手出手。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, RzPanel, StdCtrls, RzEdit;type
TfrmMarkScore = class(TForm)
private
LblArray : Array[1..100] of TLabel;
edtArray : Array[1..100] of TEdit;
public
iMainid:integer;
end;var
frmMarkScore: TfrmMarkScore;implementation
uses uDataModule;{$R *.dfm}{ TfrmMarkScore }procedure TfrmMarkScore.CreateComponent;
var
i: integer;
begin
for i := 0 to dataBase.adoDtCreate.RecordCount - 1 do
begin
LblArray[i] := TLabel.Create(nil);
LblArray[i].Name := 'lbl'+IntToStr(i);
LblArray[i].Caption := dataBase.adoDtCreate.Fields[0].AsString+':';
LblArray[i].Left := 48;
LblArray[i].Top := 24+i*64;
LblArray[i].Visible := true;
LblArray[i].Show; EdtArray[i] := Tedit.Create(nil);
EdtArray[i].Name := 'edt'+IntToStr(i);
EdtArray[i].Left := 48;
EdtArray[i].Top := 48+i*64;
EdtArray[i].Visible := true;
EdtArray[i].OnKeyPress := OnkeyPress;
EdtArray[i].Show;
end;
end;以上是代码,但showmodal, 界面出来了,但创建的控件就是看不到,求高手出手。
和
EdtArray[i].Parent:=self;即可。上两句的作用是设置父窗体,否则系统不知道应该显示在哪里。
LblArray[i].Parent := panel1;
EdtArray[i].Parent := panel1;但提示错误:“a control cannot have itself as its parent"
unit uMarkScore; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, RzPanel, StdCtrls, RzEdit; type
TfrmMarkScore = class(TForm)
panel1:Tpanel;
private
LblArray : Array[1..100] of TLabel;
edtArray : Array[1..100] of TEdit;
public
iMainid:integer;
end; var
frmMarkScore: TfrmMarkScore; implementation
uses uDataModule; {$R *.dfm} { TfrmMarkScore } procedure TfrmMarkScore.CreateComponent;
var
i: integer;
begin
for i := 0 to dataBase.adoDtCreate.RecordCount - 1 do
begin
LblArray[i] := TLabel.Create(nil);
LblArray[i].Name := 'lbl'+IntToStr(i);
LblArray[i].Caption := dataBase.adoDtCreate.Fields[0].AsString+':';
LblArray[i].Left := 48;
LblArray[i].Top := 24+i*64;
LblArray[i].Visible := true;
LblArray[i].Show;
LblArray[i].parent := panel1
EdtArray[i] := Tedit.Create(nil);
EdtArray[i].Name := 'edt'+IntToStr(i);
EdtArray[i].Left := 48;
EdtArray[i].Top := 48+i*64;
EdtArray[i].Visible := true;
EdtArray[i].OnKeyPress := OnkeyPress;
EdtArray[i].Show;
EdtArray[i].parent := panel1;
end;
end; 但提示错误:“a control cannot have itself as its parent"
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
LblArray : Array[1..100] of TLabel;
edtArray : Array[1..100] of TEdit; public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
for i := 0 to 10 do
begin
LblArray[i] := TLabel.Create(nil);
LblArray[i].Name := 'lbl'+IntToStr(i);
LblArray[i].Caption := IntToStr(i)+':';
LblArray[i].Left := 48;
LblArray[i].Top := 24+i*64;
LblArray[i].Visible := true;
LblArray[i].Show;
LblArray[i].parent := panel1;
EdtArray[i] := Tedit.Create(nil);
EdtArray[i].Name := 'edt'+IntToStr(i);
EdtArray[i].Left := 48;
EdtArray[i].Top := 48+i*64;
EdtArray[i].Visible := true; EdtArray[i].Show;
EdtArray[i].parent := panel1;
end;end;end.这段代码经测试没有问题,你看看其他的地方。
你调用的地方
LblArray[i].parent := panel1;
理论上,这两句应该调下位置,在显示之前设置好属性,其它看不出有什么问题
望高人指点