Recent

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

CCRDude

  • Hero Member
  • *****
  • Posts: 596
Re: Form event "aftershow"
« Reply #15 on: May 22, 2018, 02:48:35 pm »
A splash screen is one possible solution, but (in my personal opinion) only suited for program start. If I were a user, I would run havoc if every time I open a dialog, there's a short splash screen showing up for a second or ten, before seeing the actual window.

Depends a lot on the design concepts you try to adhere to of course, but (again just imho) a waiting display state for the form is more user friendly than splash screens.
And if you have multiple non-modal forms for example, a splash screen is even more out of question (again: imho!).

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Form event "aftershow"
« Reply #16 on: May 22, 2018, 04:03:09 pm »
I would also not use a splash screen bur rather a screen that tells you that some thing is happening in the background. And yes a progress bar could be helpful .
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

Thaddy

  • Hero Member
  • *****
  • Posts: 14169
  • Probably until I exterminate Putin.
Re: Form event "aftershow"
« Reply #17 on: May 22, 2018, 04:10:26 pm »
Since Prince is pushing up daisies and the Stones need to go to sleep on time, there will be no aftershow.... Bad event. Doomed.
« Last Edit: May 22, 2018, 04:12:06 pm by Thaddy »
Specialize a type, not a var.

Thaddy

  • Hero Member
  • *****
  • Posts: 14169
  • Probably until I exterminate Putin.
Re: Form event "aftershow"
« Reply #18 on: May 22, 2018, 04:15:45 pm »
I would also not use a splash screen bur rather a screen that tells you that some thing is happening in the background. And yes a progress bar could be helpful .
Like uhhh, cursor crHourglass, maybe? (OK retro but it works and is good design).
Specialize a type, not a var.

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Form event "aftershow"
« Reply #19 on: May 24, 2018, 06:50:40 am »
Multiple threads is not the solution: the app make several https request and is tested and probed that it throws multiple and unexpected errors on runtime.
A modal screen with a simple "Loading, Please Wait" will be enough good; the long process will not take more than 10 seconds, so a progress bar is not really necessary.

How i could implement it? I created a new form "modal", with a nice panel in the center with the message; i set the borders properly and show and the ownerform center. I the do this:

formmodal.showmodal;
Application.ProcessMessages;

(Do the long process here...)

formmodal.close;

The modal form is show in the center as expected, but the app hangs?

Im failing in the aproaching or in the code?
« Last Edit: May 24, 2018, 06:52:43 am by torbente »
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

balazsszekely

  • Guest
Re: Form event "aftershow"
« Reply #20 on: May 24, 2018, 09:26:59 am »
Quote
Multiple threads is not the solution: the app make several https request and is tested and probed that it throws multiple and unexpected errors on runtime.
At least you can create a worker thread. It won't increase the speed of the http requests, but the application will be more responsive.

Quote
How i could implement it? I created a new form "modal", with a nice panel in the center with the message; i set the borders properly and show and the ownerform center.
Please test attached project. You should modify the worker thread Execute method(uHttpRequest). Basically all you have to do is add the requests and modify the counter.
« Last Edit: May 24, 2018, 09:37:23 am by GetMem »

torbente

  • Sr. Member
  • ****
  • Posts: 325
    • Noso Main Page
Re: Form event "aftershow"
« Reply #21 on: May 25, 2018, 02:30:20 am »
I finally adopted a very simple solution:

A Timer executed 1 milisecond after the form loads.
Then a Panel in the center of the form with a label "please wait"  is set to visible := true;
form.enabled := false;
... do the long process....
panel.visible := false;
form.enabled := true;

Maybe it is not the best solution, but it is very efective.

Thanks to you all for your replies.
If i had to include something in "to do" for lazarus, i will start with a "aftershow" event for forms.
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

vrull

  • Full Member
  • ***
  • Posts: 118
Re: SOLVED: Form event "aftershow"
« Reply #22 on: May 25, 2018, 06:46:09 am »
Maybe too late...
The last event after form creation is OnActivate, although OnShow may work as well. In one of these events send a custom message to the form, like
Code: Pascal  [Select][+][-]
  1. const
  2.   LM_READDATA = LM_USER + 1234;
  3.  
  4. type
  5.   TMyForm = class(TForm)
  6.    .....
  7.    procedure FormActivate(Sender : TObject);
  8.    procedure LMREADDATA(var Msg : TMessage); message LM_READDATA;
  9.    end;
  10.  
  11. var
  12.   MyForm : TMyForm;
  13. implementation
  14.  
  15. procedure TMyForm.FormActivate(Sender : TObject);
  16. begin
  17.   PostMessage(self.Handle, LM_READDATA, 0, 0);
  18. end;
  19.  
  20. procedure TMyForm.LMREADDATA(var Msg : TMessage);
  21. begin
  22.   Msg.Result := 1;
  23.   // do you long operation here
  24. end;
  25.  
  26.  

When the form receives the message it must be already visible, so the user knows that something going on. You can even place a label saying like "Loading data...", then hide it.

 

TinyPortal © 2005-2018