Free Pascal 中是否有 delphi ScrollInView 等效项?

Is there a delphi ScrollInView equivalent in Free Pascal?

我有一个 ScrollBox,我在运行时向它添加控件。但是,当控件超过ScrollBox的高度时,我想让ScrollBox一直滚动到底部,这样新添加的控件才可见。

经过一些研究,我为 delphi 找到了一个名为 "ScrollInView" 的东西。看到 Free Pascal 中有多少(相当多)Delphi methods/functions 可用,您知道与这个特定的等效吗?如果没有,你能用不同的解决方案帮助我实现我的目标(将 ScrollBox 自动滚动到底部)吗?

提前致谢,

奥斯卡

是这样的吗?

procedure TForm1.Button1Click(Sender: TObject);
begin
    with TEdit.Create(Self) do
    begin
        Parent := ScrollBox1;
        Left := 10;
        Top := ScrollBox1.ControlCount * 40;
        ScrollBox1.VertScrollBar.Position := Top;
    end;
end;

下面是 ScrollInView 方法的简单实现:

TScrollBoxHelper = class helper for TScrollBox
    procedure ScrollInView(AControl: TControl);
end;

implementation

procedure TScrollBoxHelper.ScrollInView(AControl: TControl);
begin
    if AControl.Parent = Self then
    begin
        Self.VertScrollBar.Position := AControl.Top;
        Self.HorzScrollBar.Position := AControl.Left;
    end;
end;

用法:

procedure TForm1.Button2Click(Sender: TObject);
begin
    ScrollBox1.ScrollInView(ScrollBox1.Controls[3]);
end;