我希望能点击一个按钮,在一个Panel上能创建DBGrid控件,
点击另一个按钮,在同样的Panel上创建别的控件。
不知道该怎么写,谢谢指点!!!

解决方案 »

  1.   

    DBGrid:=TDBGrid.create(Self);
    DBGrid.Parent:=Panel;
      

  2.   

    创建一个显示对象需要设置其Parent属性:
    var
      DBGrid1:TDBGrid;
    begin
      DBGrid1 := TDBGrid.create(panel1);
      DBGrid1.parent := panel1;
      //然后设置其显示各项属性,  
    end;
    列设置:
    DBGrid1.Columns.Add;
    DBGrid1.Columns.Items[0].FieldName := 'Sdrq';
    DBGrid1.Columns.Items[0].Title.Caption := '收订日期';
    DBGrid1.Columns.Items[0].Width := 110;
    DBGrid1.Columns.Items[0].Alignment := taRightJustify;
    DBGrid1.Columns.Items[0].Title.Alignment := taCenter;
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, Grids;type
      TForm1 = class(TForm)
        Panel1: TPanel;
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
    uses
      DBGrids;
    {$R *.dfm}
    var
    DBGrid:TDBGrid ;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    if not assigned(DBGrid) then
    begin
      DBGrid:=TDBGrid.Create(Self);
      DBGrid.Parent:=Panel1;
    end;
    end;end.
      

  4.   

    DBGrid:=TDBGrid.Create(Self);
      DBGrid.Parent:=Panel1;
    精华吖,不要分,随便跟一下的
      

  5.   

    var
      MYgrid : TDBGrid;
    begin
      Mygrid := TDBGrid.Create(Self);
      with MyGrid do
      begin
        Parent:= Form1;
        Top := Form1.Top + 100 ;
        Left := Form1.Left + 20 ;
        Width := 100;
        Height := 20;
      end;
    end;
      

  6.   

    //tdbgrid是其类名
    //创建其他控件也是一样的原理,只要改变类名就可以了
    //parent属性是表示创建的控件放在什么容器上面
    var
      DBGrid1:TDBGrid;
    begin
      DBGrid1 := TDBGrid.create(self);
      DBGrid1.parent := panel1;
      //然后设置其显示各项属性,  
    end;
      

  7.   

    DBGrid:=TDBGrid.Create(Self);
    DBGrid.Parent:=Panel1;