Soon Santos
Soon Santos

Reputation: 2219

How clear all forms and open a new one in Firemonkey?

Let's suppose the user is navigating throughout an Android/iOS app and open the following forms:

Form A --> Form B --> Form C

In Form C he press a button to logout from the app. This should clear all the previous forms (including Form C) and open a new Form (Signin Form D).

So it would be something like that:

  1. Form A --> Form B --> Form C --> Press Logout Button
  2. Close Form A, B and C
  3. Open Form D
  4. Now if the user press the back button in Form D the app will be closed because there are no more forms in the task.

I tried to open Form D and close previous ones but it didn't freed completely the previous forms. Anyway to achieve this for Android/iOS?

Upvotes: 1

Views: 1201

Answers (3)

M Eugene
M Eugene

Reputation: 42

Did you fix that?

Can use on next:

procedure TfrmMain.FormKeyDown(Sender: TObject; var Key: Word;
  var KeyChar: Char; Shift: TShiftState);
begin
  if Key = vkHardwareBack then
  begin
    Key := 0;
  end;

end;

Upvotes: 1

Soon Santos
Soon Santos

Reputation: 2219

@SilverWarior was indeed correct. The problem was that Form A kept always being the ApplicationMainForm, therefore it couldn't be closed. However, as @Remy Labeau and @Tom Brunberg said. The MainForm can be changed during application runtime.

To deal with this problem I used the code below. Suppose I am in Form A and I want navigate to Form B and close previous form.

if not Assigned(frmFinanceiro) then
  frmFinanceiro := TfrmFinanceiro.Create(Application);
Application.MainForm := frmFinanceiro;
frmFinanceiro.Show;
Close;

Upvotes: 1

SilverWarior
SilverWarior

Reputation: 8331

I'm afraid this won't work exactly as you imagined. Why?

In Delphi application the first form that is created becomes Application MainForm. Closing this form then closes the entire application.

Now in your case you say that the Form A is the first form that is opened meaning that it automatically becomes the MainForm of your application. Thus closing it will close your application.

So in order to achieve what you want you will have to make sure that your Form D is actually the first form that is created in your application.

Upvotes: 2

Related Questions