Search code examples
delphifiremonkeydelphi-xe8

Firemonkey TVertScrollBox alternative to VCL ScrollBox ScrollInView


I am using Delphi XE8 to develop an Android application, and I want to move the ViewportPosition of a VertScrollBox when a button is clicked, to see a specific component (somewhere in the VertScrollBox).

But set the value of ViewportPosition does not work (I tried the answer here : Go Top a TVertScrollBox) and the method ScrollBy does not work neither (http://docwiki.embarcadero.com/Libraries/Seattle/en/FMX.Layouts.TVertScrollBox).

I tried this :

procedure TFormTournee.T3ButtonBackToTopClick(Sender: TObject);
begin
    T1VertScrollBox.ViewportPosition := PointF(T1VertScrollBox.ViewportPosition.X, 0);
    T1VertScrollBox.RealignContent;
end;

And that :

procedure TFormTournee.T3ButtonBackToTopClick(Sender: TObject);
begin
    T1VertScrollBox.ScrollBy(0,-100);
    T1VertScrollBox.RealignContent;
end;

For now, I just tried on Windows (I have to fix an other problem on Android about insufficient storage), but nothing change when I click, and it is supposed to work the same on Windows and Android, isn't that right ? So can anybody help me, please ? Or perhaps explain me what I am doing wrong ? Thanks !


Solution

  • So, if there is someone trying to program a scroll in a TVertScrollBox, with ScrollBy or ViewportPosition, and if it is not working, @loki 's link in the comments refer to an alternative working on Windows and Android (I cannot try on iOS but it is supposed to work too) (https://svn.code.sf.net/p/alcinoe/code/). I had to do a few adjustments because I am working on Delphi XE8, but it was really quick.

    On that procedure, the button click positionned the VertScrollBox on the component Panel:

    procedure TFormTournee.ButtonClick(Sender: TObject);
    begin
        // The position is placed at the top
        ALVertScrollBox1.ScrollBy(0, ALVertScrollBox.Width);
        // And then it go down to the panel position
        ALVertScrollBox1.ScrollBy(0, -Panel.Position.Y);
    end;
    

    Once more, thank you @loki !