1

我正在尝试动态操作 TGridPanelLayout。为什么这段代码不起作用?它没有显示任何东西 - 网格是空白的。

  self.OverviewGrid.RowCollection.Clear;
  self.OverviewGrid.ColumnCollection.Clear;
  self.OverviewGrid.ColumnCollection.Add;
  self.OverviewGrid.ColumnCollection.Items[0].SizeStyle:=TGridPanelLayout.TSizeStyle.Absolute;
  self.OverviewGrid.ColumnCollection.Items[0].Value:=100;
  for i := 0 to length(Array_Grid_Labels)-1 do
  begin
    t:=TButton.Create(self);
    t.Align:=TAlignLayout.Client;
    t.Text:='test';
    t.Font.Size:=11;
    t.FontColor:=TAlphaColors.Black;
    self.OverviewGrid.RowCollection.Add;
    self.OverviewGrid.RowCollection.Items[i].SizeStyle:=TGridPanelLayout.TSizeStyle.Absolute;
    self.OverviewGrid.RowCollection.Items[i].Value:=30;
    self.OverviewGrid.ControlCollection.AddControl(t,0,i);
  end;

使用 Delphi Seattle 开发 iOS/Android (FMX)

要注意:

 self.OverviewGrid.AddObject(t);

确实给了我想要的结果,但这仍然让我无法以上面显示的所需方式操作网格。

4

2 回答 2

0

尝试显式设置子控件的父级:

t.FontColor:=TAlphaColors.Black;
t.Parent:=self.OverviewGrid;              // +++
self.OverviewGrid.RowCollection.Add;
于 2015-11-24T04:30:20.190 回答
0
t.Parent := OverviewGrid;
OverviewGrid.Controls.Add(vppLayout);

在德尔福西雅图 FMX 为我工作

于 2016-01-22T19:47:28.403 回答