smart-mobile-studio

Navigating forms using layouts in multiple layout orientations?


I have a project with a number of forms. I use Layouts on all my forms.

Each form has essentially the same code (see below) for when I am navigating between them.

Application.GotoForm('frmInventory', feFromRight);

Everything is great until I change orientations (e.g. from profile to landscape). Then the Layouts get screwed up.

see screenshot1 versus screenshot2.

Example Code:

procedure TfrmMenu.frmMenuDeactivate(Sender: TObject);
begin
 fLayout:= nil;
end;


procedure TfrmMenu.frmMenuActivate(Sender: TObject);
begin
 fLayout:= Layout.Client([Layout.Top(fHeader),
                           Layout.Bottom(fFooter),
                           Layout.Client(fList)]);
end;


procedure TfrmMenu.Resize;
begin
  inherited;
   if assigned(FLayout) then
   begin
    fLayout.Resize(self)
   end;
end;

That is correct! Why isn't it. What am i missing? How do you capture the orientation change?

----- UPDATE -----

Searching on this site, I cam across this article:

http://www.thedelphigeek.com/2012/02/detecting-device-movement.html

which then led me to this stackoverflow answer:

Access accelerometer via Javascript in Android?

 if (window.DeviceMotionEvent == undefined) {
        //No accelerometer is present. Use buttons. 
        alert("no accelerometer");
    }
    else {
        alert("accelerometer found");
        window.addEventListener("devicemotion", accelerometerUpdate, true);
    }

in SMS, this seems to do it:

function window: variant; external 'window' property;

procedure TfrmItem.InitializeObject;
begin
  inherited;
  {$I 'Item:impl'}
  window.addEventListener('devicemotion', @Resize, false);
  .
  .
  .
end;

procedure TfrmItem.Resize;
begin
  inherited;
  if assigned(fLayout) then
  begin
    fLayout.Resize(self);
    ResizeControls;
  end;
end;

Solution

  • Searching on this site, I cam across this article:

    http://www.thedelphigeek.com/2012/02/detecting-device-movement.html

    which then led me to this stackoverflow answer:

    Access accelerometer via Javascript in Android?

     if (window.DeviceMotionEvent == undefined) {
            //No accelerometer is present. Use buttons. 
            alert("no accelerometer");
        }
        else {
            alert("accelerometer found");
            window.addEventListener("devicemotion", accelerometerUpdate, true);
        }
    

    in SMS, this seems to do it:

    function window: variant; external 'window' property;
    
    procedure TfrmItem.InitializeObject;
    begin
      inherited;
      {$I 'Item:impl'}
      window.addEventListener('devicemotion', @Resize, false);
      .
      .
      .
    end;
    
    procedure TfrmItem.Resize;
    begin
      inherited;
      if assigned(fLayout) then
      begin
        fLayout.Resize(self);
        ResizeControls;
      end;
    end;