Recent

Author Topic: What after showModal Form gets closed  (Read 988 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
What after showModal Form gets closed
« on: October 29, 2020, 04:25:57 pm »
Hey Guys,

Just a short Question:

So this is a part of  my code :D

Code: Pascal  [Select][+][-]
  1.         ZubAll.ShowModal;
  2.         If ZubAll.Sprung.Caption = 'ABB' Then Begin
  3.            calculated := False;
  4.            Break;
  5.         End;
  6.  

it is calling a Normal Form where i imediately press Abort (its a Button) to get back (its a form where i can select extras for my produkt)

this is the code of the button:

Code: Pascal  [Select][+][-]
  1. procedure TZubAll.Command1_Click(Sender: TObject);
  2. begin
  3.   Sprung.Caption:= 'ABB';
  4.   //TODO ErrorHandling
  5.   //TODO Close DB Connections (Werte + Texte)
  6.   ZubAll.Hide;
  7. end;
  8.  

My problem is that after this code nothing happens.
Do i have to call main Form again ? but how will i get to this point in my code where i called the second Form ?

i dont get it how i get back to the part i was calling ShowModal after i exit this form.

Please some Help i am very Newbie to Lazarus sorry thanks  :)
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: What after showModal Form gets closed
« Reply #1 on: October 29, 2020, 05:46:04 pm »
You need to call Close. Or even better set the ModalResult value. Then you will get this value when calling ShowModal.
Conscience is the debugger of the mind

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: What after showModal Form gets closed
« Reply #2 on: October 29, 2020, 06:31:12 pm »
Calling Hide makes the form "disssapear" but it's still there, and since it is shown modally the focus can't return to the caller.

As Circular says, you have to close the modal form either calling Close or, which is better, setting its ModalResult which incidentally also closes it.

By the way, you should check the result of ShowModal to allow for the user closing the form without doing anything or clicking a "cancel" button or similar:

Code: Pascal  [Select][+][-]
  1.         if (ZubAll.ShowModal = mrOK) {or mrYes or whatever}
  2.         and (ZubAll.Sprung.Caption = 'ABB') Then Begin
  3.            calculated := False;
  4.            Break;
  5.         End;
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: What after showModal Form gets closed
« Reply #3 on: October 30, 2020, 08:09:04 am »
Thanks Guys :)
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

 

TinyPortal © 2005-2018