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, 界面出来了,但创建的控件就是看不到,求高手出手。

解决方案 »

  1.   

    分别加上:LblArray[i].Parent:=self;

    EdtArray[i].Parent:=self;即可。上两句的作用是设置父窗体,否则系统不知道应该显示在哪里。
      

  2.   

    我希望这些动态创建在panel上,于是我这样设置:
      LblArray[i].Parent := panel1;
      EdtArray[i].Parent := panel1;但提示错误:“a control cannot have itself as its parent"
      

  3.   

    名字不需要设置的没看你定义了panel1
      

  4.   

    有定义panel1,全代码如下:
    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"
      

  5.   

    unit Unit1;interfaceuses
      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.这段代码经测试没有问题,你看看其他的地方。
    你调用的地方
      

  6.   

       LblArray[i].Show; 
       LblArray[i].parent := panel1;
    理论上,这两句应该调下位置,在显示之前设置好属性,其它看不出有什么问题
      

  7.   

    我是在窗体的FormShow中调用这个方法的,提示错误:“a control cannot have itself as its parent" 
    望高人指点