Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread How to know where you are
Mon, Aug 25 2014 5:00 PMPermanent Link

Sergei Safar

Hi,

which is the best way to know if we are under a PC, Smartphone or Tablet / Ipad ? I need to resize my app depending on the screen size available.

Best regards,
Sergei Safar
Tue, Aug 26 2014 3:43 AMPermanent Link

Matthew Jones

Sergei Safar wrote:

> which is the best way to know if we are under a PC, Smartphone or
> Tablet / Ipad ? I need to resize my app depending on the screen size
> available.

In your main FormCreate, add:

   Application.Desktop.OnResize := DesktopResized;

procedure TfrmMain.DesktopResized(Sender : TObject);
var
   nWidth : Integer;
   nHeight : Integer;
   nMoveLeft : Integer;
begin  
   try

       nWidth := Application.Desktop.Width;
       nHeight := Application.Desktop.Height;

       if Width > nWidth then
       begin
.....

Also, add the standard event handler for form resize:

procedure TfrmJoin.frmJoinResize(Sender: TObject);
begin
   DesktopResized(nil);
end;

You can then determine if you are in portrait or landscape, and move
things according to the size.

For one application I appear to have this on a timer, so the resize
starts the timer, and then the timer does the movement. That may have
been some quirk of rotation on a particular tablet. A fallback option
if you find an issue.

Finally, you can check particular aspects of things using the user
agent string. Print out the string to find details for a particular
device.

   if Pos('Android', window.navigator.useragent) > 0 then

--

Matthew Jones
Image