程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> delphi-Delphi 動態創建GridPanel

delphi-Delphi 動態創建GridPanel

編輯:編程解疑
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

最佳回答:


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;

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved