Recent

Author Topic: [SOLVED] Need a Form, partly modal and partly non modal  (Read 516 times)

Hartmut

  • Hero Member
  • *****
  • Posts: 1007
[SOLVED] Need a Form, partly modal and partly non modal
« on: October 09, 2025, 11:34:25 am »
In my program sometimes I need to show a message to the User, that he now has to wait, until certain jobs have been finished, before he can proceed.

On one side, I need something like a non modal Form, because:
 - a modal Form would stop the execution of that jobs
 - and I need a loop, which repeatedly checks, whether all jobs have been finished, and if yes, this message should be closed (by code) and the user can proceed.

On the other side, I need something like a modal Form, because I want to prevent, that the user can operate any GUI-Controls of all currently open Forms, as long as this message is displayed. Without a modal Form it would be very laborious, do deactivate all these GUI-Controls one by one and to reactivate all again later to their formerly state. Or I would need another way to prevent the Form with the message loosing it's focus to another Form of my program (but switching to another program should be allowed).

Multitasking is not an option, because these jobs, which the user has to wait for, do a lot of output to several GUI-Controls (and adding multitasking to this bigger and complex project would be much to laborious and very dangerous).

A solution should work on Windows and Linux and with Lazarus 2.0.10, because it is an older project. Thanks in advance.
« Last Edit: October 09, 2025, 06:21:23 pm by Hartmut »

Handoko

  • Hero Member
  • *****
  • Posts: 5487
  • My goal: build my own game engine using Lazarus
Re: Need a Form, partly modal and partly non modal
« Reply #1 on: October 09, 2025, 12:04:27 pm »
Maybe TAction?

I do not use it but I ever tried it in the past, setting all processes as actions and associate them with menu items and buttons. As far as I remember, I can disable certain actions when an action is running. Perhaps it is what you need.

https://wiki.freepascal.org/TAction

Hartmut

  • Hero Member
  • *****
  • Posts: 1007
Re: Need a Form, partly modal and partly non modal
« Reply #2 on: October 09, 2025, 12:48:53 pm »
Thanks Handoko for this suggestion. Until now I never used TAction. From what you wrote and what I read in your link, I assume, that TAction woudn't help me:
 - some of the jobs, which the user has to wait for, are started by remote communication situations with other computers and not via buttons, menues etc.
 - my need is not, to stop an "action", my need is to prevent, that the user can operate any GUI-Controls of all currently open Forms (as long as these jobs have not been finished and a message about that is displayed).

cdbc

  • Hero Member
  • *****
  • Posts: 2466
    • http://www.cdbc.dk
Re: Need a Form, partly modal and partly non modal
« Reply #3 on: October 09, 2025, 01:39:09 pm »
Hi
I do this in an app, where I wait for frames to finish... Here's the main unit attached.

· Basically I've got _all_ my controls together on 1 groupbox.
· I have a 'fFrameWait' variable, that I set before disabling the groupbox
· While the page/tab-frame is active it has all focus, you can't even close app
· When page/tab-frame is finished it posts a message to the main-form,
  which then releases the lock on the groupbox and hence the controls.
· The logic/mechanics are shown throughout the attached form-code...
I think you could do the same with your code  ...and there are no threads involved (only main).
HTH  :D
Regards Benny
« Last Edit: October 09, 2025, 04:51:48 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6 -> FPC 3.2.2 -> Lazarus 4.0 up until Jan 2025 from then on it's both above &: KDE6/QT6 -> FPC 3.3.1 -> Lazarus 4.99

Hartmut

  • Hero Member
  • *****
  • Posts: 1007
Re: Need a Form, partly modal and partly non modal
« Reply #4 on: October 09, 2025, 04:46:09 pm »
Thanks Benny for this idea and your demo. I had a look at it and think, that your 'fWaitState' variable instead is named 'fFrameWait'.

My Main-Form has a lot of static and a lot of dynamic Controls. To switch all of them onto a groupbox retroactive would be not easier than to write a procedure, which sets the Enable-Property of all those Controls to True respective False. And I fear the groupbox solution because of 2 risks (which I both would face, when it was too late):
 - The positions of all Controls are variable (by a couple of parameters) and if values had to be adapted because of the groupbox then this would increase my effort a lot.
 - Several Mouse-Events for a lot of Panel-arrays and Image-arrays (partly placed on Panels, which are partly placed on other Panels) must compute the correct Control (and correct array index) which was clicked. If anything of this would need to be adapted because of the groupbox, then this would increase my effort enormous.

I'm hoping more for a solution to prevent the non modal Form (which displays the message) to loose it's focus to another Form of my program (but switching to another program should be allowed).

Thaddy

  • Hero Member
  • *****
  • Posts: 18344
  • Here stood a man who saw the Elbe and jumped it.
Re: Need a Form, partly modal and partly non modal
« Reply #5 on: October 09, 2025, 04:57:53 pm »
modal won't stop execution when the work is done in a thread.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

LeP

  • Jr. Member
  • **
  • Posts: 57
Re: Need a Form, partly modal and partly non modal
« Reply #6 on: October 09, 2025, 05:08:50 pm »
Sometimes ago, when Microsoft deprecated the Modal forms and Delphi support on those were not so clean, I used to show a FORM big as all main form with property FormStyle set to  fsStayOnTop, with some text animated too (like WAITING ....) and close it when it doesn't need anymore.

Hartmut

  • Hero Member
  • *****
  • Posts: 1007
Re: Need a Form, partly modal and partly non modal
« Reply #7 on: October 09, 2025, 05:42:08 pm »
@ Thaddy
Why do you bombard me - again and again - with so absolute useless posts?

If you would have read only my 1st post - obviously again you did not - then you would know, that and why I do not want threads.

Do you have to accomplish your post counter to a certain value before end of year and don't know how to reach this with usefull posts?



Thank you LeP for this suggestion. It sounded interesting and I tested it.

Unfortunately, when I click in this state in the taskbar on the entry for the "big form in front", then it disappears and the "hidden form" becomes visible and can be clicked (Linux Ubuntu 24.04). Another disadvantage would be, that 1 of the multiple currently open Forms should stay visible to the User, because it shows the progress of the running jobs.

LeP

  • Jr. Member
  • **
  • Posts: 57
Re: Need a Form, partly modal and partly non modal
« Reply #8 on: October 09, 2025, 05:52:02 pm »
Uhmm ... and set all visible forms (only forms) in disable state ?

All controls still work (show the data) but don't accept any input.

Hartmut

  • Hero Member
  • *****
  • Posts: 1007
Re: Need a Form, partly modal and partly non modal
« Reply #9 on: October 09, 2025, 06:20:59 pm »
YES! That's great! I did a quick test on Windows and Linux and is does exactly what I want. All Controls get disabled, but new data is continuously displayed. And it is very easy: only 1 command per visible Form :-))

Thank you very much LeP.

 

TinyPortal © 2005-2018