qq_30877677
2016-01-25 02:06
采纳率: 36.7%
浏览 3.2k
已采纳

Delphi 动态创建GridPanel

Delphi 如何动态创建GridPanel
procedure TForm12.FormCreate(Sender: TObject);
var
grdpnl: TGridPanel;
lbl: TLabel;
img: TImage;
begin
grdpnl := TGridPanel.Create(self);
grdpnl.Parent := pnl1;
grdpnl.Align := alTop;
grdpnl.Height := 38;
grdpnl.Caption := 'grdpnl1';
// grdpnl.BevelOuter := bvNone;
grdpnl.ColumnCollection.Add.SizeStyle := ssAbsolute;
grdpnl.ColumnCollection.Add.Value := 10;
grdpnl.ColumnCollection.Add.SizeStyle := ssAbsolute;
grdpnl.ColumnCollection.Add.Value := 50;
grdpnl.ColumnCollection.Add.SizeStyle := ssAbsolute;
grdpnl.ColumnCollection.Add.Value := 10;
grdpnl.ColumnCollection.Add.SizeStyle := ssPercent;
grdpnl.ColumnCollection.Add.Value := 100;
grdpnl.ColumnCollection.Add.SizeStyle := ssAbsolute;
grdpnl.ColumnCollection.Add.Value := 40;
grdpnl.RowCollection.Add.SizeStyle := ssPercent;
grdpnl.RowCollection.Add.Value := 50;
grdpnl.RowCollection.Add.SizeStyle := ssAbsolute;
grdpnl.RowCollection.Add.Value := 17;
grdpnl.RowCollection.Add.SizeStyle := ssPercent;
grdpnl.RowCollection.Add.Value := 50;
//创建lbl
lbl := TLabel.Create(grdpnl);
lbl.Parent := grdpnl;
lbl.Left := 10;
lbl.Top := 10;
lbl.Width := 50;
lbl.Height := 17;
lbl.Align := alClient;
lbl.Caption := '张自力';
lbl.Font.Name := '微软雅黑';
lbl.Font.Color := $00333333;
lbl.Font.Charset := GB2312_CHARSET;
lbl.Font.Size := 9;
lbl.Layout := tlCenter;
这样写不起作用啊,还有Label应该如何分配Colum和Row

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • DieGhost 2016-06-06 17:54
    已采纳

    grdpnl: TGridPanel;
    lbl: TLabel;
    img: TImage;

    声明放到全局去,局部的过程执行完被自动释放了。

    var
    grdpnl: TGridPanel;
    lbl: TLabel;
    img: TImage;

    procedure TForm12.FormCreate(Sender: TObject);
    begin
    //创建代码
    end;

    procedure TForm12.FormDestroy(Sender: TObject);
    begin
    grdpnl.free;
    lbl.free;
    img.free;
    end;

    已采纳该答案
    打赏 评论
  • threenewbee 2016-01-25 21:27
    打赏 评论

相关推荐 更多相似问题