Recent

Author Topic: OnActivate event doesn't work as advertised? :)  (Read 3438 times)

osp

  • New Member
  • *
  • Posts: 16
OnActivate event doesn't work as advertised? :)
« on: November 28, 2014, 01:20:55 pm »
Hello,
I build a tiny app, which do something (communicate via external program to server) when button is clicked and it takes some sec to finish. So I am trying to create simple little window with progress bar (left-right moving rectangle) and "Please, wait" text.

So there is a button which calls showmodal on that please-wait form and on onactivate event of this form is calling to my procedure which does the actual work and in it at the end is a call "hide" on please-wait form.

According to this:
http://wiki.lazarus.freepascal.org/Event_order

OnActivate event means, that form is already up and running and visible, am I right? But when I run my app, after pressing button I know that my working method is fired (app is frozen), then it is finished (I have result) and finally then a gray rectangle of size of my please-wait window just flashes and dissappear without even being paint properly.

I very possible do this wrong way, but I need just simple thing: I have one procedure which does something for some time. That procedure will be fired after button is pressed. And I need immediately after button is pressed to show a please-wait form in a way, that it will block a main window and only after it is visible and up, my working method will be fired.

In mainform there is button event:
Code: [Select]
procedure TmainForm.ButtonConnectClick(Sender: TObject);
begin
  FormWait.Showmodal;
end;   

Here is a whole please-wait form unit:
Code: [Select]
{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls;

type

  { TFormWait }

  TFormWait = class(TForm)
    ProgressBar1: TProgressBar;
    procedure FormActivate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  protected
  end;

var
  FormWait: TFormWait;

implementation

{$R *.lfm}

uses
  uMainForm;

{ TFormWait }

procedure TFormWait.FormActivate(Sender: TObject);
begin
  mainForm.Reload;
end;

end. 

and the reload procedure is the actual working method of mainform and it has at the end:
Code: [Select]
FormWait.Hide;
Can someone help me with this?

P.S. sorry for grammar and coding style - it is just quick&dirty little app.
The Eagle Does Not Catch Flies

sam707

  • Guest
Re: OnActivate event doesn't work as advertised? :)
« Reply #1 on: November 28, 2014, 01:35:27 pm »
insert some

Application.ProcessMessages;

in your reload procedure

osp

  • New Member
  • *
  • Posts: 16
Re: OnActivate event doesn't work as advertised? :)
« Reply #2 on: November 28, 2014, 01:37:03 pm »
I am actually not very skilled in lazarus/freepascal - could you give me some hints? What is the purpose and how to use it? :)

Thanks
The Eagle Does Not Catch Flies

sam707

  • Guest
Re: OnActivate event doesn't work as advertised? :)
« Reply #3 on: November 28, 2014, 01:39:12 pm »

osp

  • New Member
  • *
  • Posts: 16
Re: OnActivate event doesn't work as advertised? :)
« Reply #4 on: November 28, 2014, 02:05:49 pm »
http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tapplication.processmessages.html

especially inside loops to let the GUI refresh!!!

Well, there was not much to read on that site, but ok, I will look that stuff up, thanks
The Eagle Does Not Catch Flies

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: OnActivate event doesn't work as advertised? :)
« Reply #5 on: November 28, 2014, 08:26:42 pm »
Well, there was not much to read on that site, but ok, I will look that stuff up, thanks
If it's more reading material you want: http://wiki.freepascal.org/Multithreaded_Application_Tutorial
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

 

TinyPortal © 2005-2018