Recent

Author Topic: SOLVED: Form event "aftershow"  (Read 6265 times)

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
SOLVED: Form event "aftershow"
« on: May 21, 2018, 06:50:54 pm »
The question is: are there something similar to an "aftershow" event towork with forms? OnCreate and OnShow executes before the form is draw. I can handle it with a little timer executed "onshow", but are there any better way to do the job?
« Last Edit: May 25, 2018, 02:30:43 am by torbente »
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

balazsszekely

  • Guest
Re: Form event "aftershow"
« Reply #1 on: May 21, 2018, 07:14:18 pm »

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Form event "aftershow"
« Reply #2 on: May 21, 2018, 09:56:10 pm »
The question is: are there something similar to an "aftershow" event towork with forms? OnCreate and OnShow executes before the form is draw. I can handle it with a little timer executed "onshow", but are there any better way to do the job?

Use Application.QueueAsyncCall() with your specific routine and it'll be called right after OnFormShow is finished.

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Form event "aftershow"
« Reply #3 on: May 22, 2018, 01:39:05 am »
The question is: are there something similar to an "aftershow" event towork with forms? OnCreate and OnShow executes before the form is draw. I can handle it with a little timer executed "onshow", but are there any better way to do the job?

Use Application.QueueAsyncCall() with your specific routine and it'll be called right after OnFormShow is finished.

First time i hear about it. I will check it.

Onshow do not solves my need; when the form is called to be shown, a long process take places and the user feels like the app is hang. As my post says, i need an "aftershow" way to do the job. (i guess zeljko solution is similar to use a timer)
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

balazsszekely

  • Guest
Re: Form event "aftershow"
« Reply #4 on: May 22, 2018, 05:14:41 am »
@torbente
Quote
Onshow do not solves my need; when the form is called to be shown, a long process take places and the user feels like the app is hang.
Well in this case I would show a modal form to the user, with a message : "Loading data. Please wait...". A progressbar would also help.

CCRDude

  • Hero Member
  • *****
  • Posts: 596
Re: Form event "aftershow"
« Reply #5 on: May 22, 2018, 07:45:38 am »
I usually use FormPaint with a flag to catch the first time it is called only.
Didn't know about Application.QueueAsyncCall before though :)

MountainQ

  • Jr. Member
  • **
  • Posts: 65
Re: Form event "aftershow"
« Reply #6 on: May 22, 2018, 08:42:52 am »
Sorry; I misinterpreted the question; you can therefore ignore my 'solution':

A very simple solution is to call a function before the application itself is started; specifically:
Code: Pascal  [Select][+][-]
  1. program project1;
  2. ...
  3. begin
  4.   ...
  5.   Application.Initialize;
  6.   Application.CreateForm(TForm1, Form1);
  7.   Form1.BeforeRun;
  8.   Application.Run;
  9. end.                              
  10.  
Naturally the main Form has to provide 'BeforeRun'
« Last Edit: May 22, 2018, 12:13:45 pm by MountainQ »

CCRDude

  • Hero Member
  • *****
  • Posts: 596
Re: Form event "aftershow"
« Reply #7 on: May 22, 2018, 09:44:09 am »
@MountainQ: if called before Application.Run, why would it show before the form is shown?

Another aspect: OO. Keep this inside the object if possible (also makes it easier to re-use the form in other projects).

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Form event "aftershow"
« Reply #8 on: May 22, 2018, 09:47:38 am »
If it takes that long put up a message on the screen that the program is busy every time it does a long 'pause'.
It's not beautiful, but very effective.
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

CCRDude

  • Hero Member
  • *****
  • Posts: 596
Re: Form event "aftershow"
« Reply #9 on: May 22, 2018, 11:02:58 am »
If it takes that long put up a message on the screen that the program is busy every time it does a long 'pause'.
It's not beautiful, but very effective.

To show that message on the form, the original form needs to show up first, that's what the OP was looking for.

It's also not effective, since if the form is working in the background, and the window could still freeze unless you use uglier workarounds like Application.ProcessMessages.

I would opt for moving extensive operations into a thread, but that's beyond the scope of this question :)

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Form event "aftershow"
« Reply #10 on: May 22, 2018, 11:42:26 am »
I would opt for moving extensive operations into a thread, but that's beyond the scope of this question :)

Only if his Form doesn't need the result of this processing to go forward.
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

CCRDude

  • Hero Member
  • *****
  • Posts: 596
Re: Form event "aftershow"
« Reply #11 on: May 22, 2018, 12:11:38 pm »
I would opt for moving extensive operations into a thread, but that's beyond the scope of this question :)

Only if his Form doesn't need the result of this processing to go forward.

Why that? That's what the threads OnTerminated event is for.

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Form event "aftershow"
« Reply #12 on: May 22, 2018, 12:18:45 pm »
If his Form needs the Result of his processing, the Form would have to wait (aka being blocked or whatever) for that Event of the thread presenting its results.

Or do i have it wrong?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

CCRDude

  • Hero Member
  • *****
  • Posts: 596
Re: Form event "aftershow"
« Reply #13 on: May 22, 2018, 12:35:57 pm »
There's some "blocking" anyway currently if I understood the OP correctly - simply in the form of the delay until the form is shown (which is irritating to the user).

If loading in a parallel thread upon opening the form, the initial state of the form would have to be something like Enabled = false.

So yes, the form UI needs to represent that it's not ready yet, but even that is way more friendly to the user, who then knows something loads (maybe even sees a progress bar if it's really heavy stuff), compared to clicking to open a form and nothing happens for a while.

I wouldn't call it "the form would have to wait", but "the form needs to change its state upon thread termination".

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Form event "aftershow"
« Reply #14 on: May 22, 2018, 12:41:36 pm »
Then his Problem sounds more like a "Splash"-Screen
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018