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;