2 qq 30877677 qq_30877677 于 2016.01.25 10:06 提问

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
DieGhost   2016.06.07 01: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;

caozhy
caozhy   Ds   Rxr 2016.01.26 05:27
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!