Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way of switching between screens in Firemonkey Android app built with Delphi?

I'm building Android app in Delphi 10.3 using Firemonkey and I need the app to have 2 different screens - Login and Main. How do I properly organize these, onto Forms, Frames, or some other way? So that Login screen got replaced with Main app screen.

So far I've created two forms and tried to toggle them by:

Form1.Hide;
Form2.Show;

but this didn't work at all, app simply closes itself.

As a workaround, I've tried to embed Form2 into Form1. This works, but I'm suspecting this is not the right way to do it:

Form1.GroupBox1.Visible := False; // all elements reside on GroupBox1
Form2.Parent := Form1;
Form2.Show;

Hence the question - How to properly setup and switch between screens in Delphi Firemonkey Android app?

P.S. I'm newbie in Android development and looking for a Delphi-way of solving this case.

Similar questions:

Show login form before main form (implies that Forms should be used, lacks the actual code)

like image 408
Kromster Avatar asked Oct 26 '25 10:10

Kromster


2 Answers

Following code (run on successfull login) looks correct from logics standpoint and seems to work well too:

// Create only Form1 on app creation
// Create Form2 on successfull login

Application.CreateForm(TForm2, Form2);
Form2.Show;
Application.MainForm := Form2;
Form1.Close;
Form1.Free;
Form1 := nil;

If there are better/proper ways of doing this, I'm eager to see them too.

like image 148
Kromster Avatar answered Oct 29 '25 00:10

Kromster


I use a single form with a TTabControl (no tabs showing), creating frames which are parented to a tab in the TTabControl, and switch between tabs to show the different frames.

One advantage of doing this is being able to do transitions, however there is one drawback that might be off-putting to some: inability to edit custom styes on frames.

like image 24
Dave Nottage Avatar answered Oct 28 '25 22:10

Dave Nottage



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!