从代码添加到 TGridPanel 时如何在两个百分比行之间有一个绝对行?

How to have an absolute row between two percentage rows when adding to a TGridPanel from code?

我正在尝试通过代码创建一个带有 TGridPanel 的表单。

它包含:

这是我写的代码:

uses
  Winapi.Messages, Winapi.Windows, System.Classes, System.SysUtils,
  System.UITypes, System.Variants, Vcl.Controls, Vcl.DBCtrls, Vcl.DBGrids,
  Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Forms, Vcl.Graphics, Vcl.Grids, Vcl.StdCtrls,
  Data.DB;

procedure Test;
var
  View: TForm;
  GridPanel: TGridPanel;
  Grid: TDBGrid;
  DataSource: TDataSource;
  Navigator: TDBNavigator;
  Memo: TMemo;
begin
  View := TForm.Create(Application);
  try
    View.Name := 'Form2';
    // SystemFont(View.Font);
    View.Width := 640;
    View.Height := 480;
    View.Position := TPosition.poOwnerFormCenter;
    GridPanel := TGridPanel.Create(View);
    GridPanel.Name := 'GridPanel';
    GridPanel.Caption := '';
    GridPanel.BevelOuter := TBevelCut.bvNone;
    GridPanel.FullRepaint := False;
    GridPanel.Parent := View;
    GridPanel.Align := TAlign.alClient;

    GridPanel.ColumnCollection.BeginUpdate;
    GridPanel.ColumnCollection.Delete(1);
    GridPanel.ColumnCollection[0].Value := 100;
    GridPanel.ColumnCollection.EndUpdate;
    GridPanel.RowCollection.BeginUpdate;
    GridPanel.RowCollection.Add;
    TCellItem(GridPanel.RowCollection[0]).Value := 50;
    TCellItem(GridPanel.RowCollection[0]).SizeStyle := TSizeStyle.ssPercent;
    TCellItem(GridPanel.RowCollection[1]).Value := 24;
    TCellItem(GridPanel.RowCollection[1]).SizeStyle := TSizeStyle.ssAbsolute;
    TCellItem(GridPanel.RowCollection[2]).Value := 50;
    TCellItem(GridPanel.RowCollection[2]).SizeStyle := TSizeStyle.ssPercent;
    GridPanel.RowCollection.EndUpdate;

    Memo := TMemo.Create(View);
    Memo.Name := 'Memo';
    Memo.Parent := GridPanel;
    Memo.Lines.Clear;
    Memo.Align := TAlign.alClient;
    DataSource := TDataSource.Create(View);
    Navigator := TDBNavigator.Create(View);
    Navigator.Name := 'Navigator';
    Navigator.DataSource := DataSource;
    Navigator.Parent := GridPanel;
    Navigator.Align := TAlign.alClient;
    Grid := TDBGrid.Create(View);
    Grid.Name := 'Grid';
    Grid.Parent := GridPanel;
    Grid.Align := TAlign.alClient;
    Grid.DataSource := DataSource;

    {
    GridPanel.ControlCollection.BeginUpdate;
    GridPanel.ControlCollection.AddControl(Memo, 0, 0);
    GridPanel.ControlCollection.AddControl(Navigator, 0, 1);
    GridPanel.ControlCollection.AddControl(Grid, 0, 2);
    GridPanel.ControlCollection.EndUpdate;
    }

    // ShowMessage(ComponentToString(View));
    View.ShowModal;
  finally
    View.Free;
  end;
end

结果如下所示:

问题:表单底部有空隙,看不到数据库导航器!

DFM 转储对我来说没问题:

object Form2: TForm
  Left = 0
  Top = 0
  Caption = 'Form2'
  ClientHeight = 441
  ClientWidth = 624
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poOwnerFormCenter
  PixelsPerInch = 96
  TextHeight = 13
  object GridPanel: TGridPanel
    Left = 0
    Top = 0
    Width = 624
    Height = 441
    Align = alClient
    BevelOuter = bvNone
    ColumnCollection = <
      item
        Value = 100.000000000000000000
      end>
    ControlCollection = <
      item
        Column = 0
        Control = Memo
        Row = 0
      end
      item
        Column = 0
        Control = Navigator
        Row = 1
      end
      item
        Column = 0
        Control = Grid
        Row = 2
      end>
    FullRepaint = False
    RowCollection = <
      item
        Value = 50.000000000000000000
      end
      item
        SizeStyle = ssAbsolute
        Value = 24.000000000000000000
      end
      item
        Value = 50.000000000000000000
      end>
    TabOrder = 0
    object Memo: TMemo
      Left = 0
      Top = 0
      Width = 624
      Height = 208
      Align = alClient
      TabOrder = 0
      ExplicitLeft = 219
      ExplicitTop = 59
      ExplicitWidth = 185
      ExplicitHeight = 89
    end
    object Navigator: TDBNavigator
      Left = 0
      Top = 208
      Width = 624
      Height = 18
      Align = alClient
      TabOrder = 1
      ExplicitTop = 0
      ExplicitWidth = 240
      ExplicitHeight = 25
    end
    object Grid: TDBGrid
      Left = 0
      Top = 208
      Width = 624
      Height = 209
      Align = alClient
      TabOrder = 2
      TitleFont.Charset = DEFAULT_CHARSET
      TitleFont.Color = clWindowText
      TitleFont.Height = -11
      TitleFont.Name = 'Tahoma'
      TitleFont.Style = []
    end
  end
  object TDataSource
  end
end

当我改变位置时,导航器处于正确的位置,但我希望它是绝对的。

TCellItem(GridPanel.RowCollection[1]).Value := 5;
TCellItem(GridPanel.RowCollection[1]).SizeStyle := TSizeStyle.ssPercent;

为什么 TGridPanel 在这种情况下表现得如此奇怪?我该怎么办?

更改设置 SizeStyle 和 Value 的顺序。

TCellItem(GridPanel.RowCollection[0]).SizeStyle := TSizeStyle.ssPercent;
TCellItem(GridPanel.RowCollection[0]).Value := 50;
TCellItem(GridPanel.RowCollection[1]).SizeStyle := TSizeStyle.ssAbsolute;
TCellItem(GridPanel.RowCollection[1]).Value := 24;
TCellItem(GridPanel.RowCollection[2]).SizeStyle := TSizeStyle.ssPercent;
TCellItem(GridPanel.RowCollection[2]).Value := 50;