Forum > General

Showing dynamically created form (Lazarus/Linux)

(1/2) > >>

odvesims:
Hey There!

Im my application I send request to a server via socket. While the whole socket request/receiving process is taking place I show a dynamically created form that essentially blocks the UI and shows a message telling the user which action is taking place. It closes after the socket's received an answer or after it's timed out.

This works perfectly under Windows, however i cant get it to work on Unix systems (Ubuntu version 10). The UI simply blocks but the form is not shown. It shows if I, for instance, put a ShowMessage in between the form "Show" method and the "Close" method.

Anyone knows why is this happening and what'd be the way to fix it.. Anyone thinking of a different approach (sure there'd be a "cleaner" way to do it, perhaps using threads? No clue there though...).

Thanks in advance,

Oscar

engkin:
Show some code.

odvesims:
Hey Engkin

It's simple, i create the Form using the following

DialogForm:= TForm.Create(Application);
DialogForm.Position:= TPosition.poMainFormCenter;
DialogForm.SetBounds(100, 100, 254, 116);
DialogForm.Caption:= 'Please, wait...';
DialogForm.AlphaBlendValue := 230; // 0..255
DialogForm.AlphaBlend := True;
DialogForm.BorderStyle:= TFormBorderStyle.bsDialog;

Then i use the DialogForm.Show command to make the TForm visible. But it's not working under UNIX systems.

eny:
Maybe adding 'Application.ProcessMessages' right after the Show helps.

garlar27:
AFAIK the form would be blocked on Windows too.

To fix that put a TTimer on your form and set the Interval to 500 ms or 1000 ms, and set Enabled to true. In the OnTimer event put this code (in case you use form disigner):

--- Code: ---Application.ProcessMessages
--- End code ---

Add this to your code:
1- Add this method to your class

--- Code: ---procedure OnTimerEvent(Sender: TObject);

procedure TMyClass.OnTimerEvent(Sender: TObject);
begin
  Application.ProcessMessages
end;

--- End code ---
2- Add the followin code to your function:

--- Code: ---var
  ....
  MyTimer: TTimer;
begin
  DialogForm:= TForm.Create(Application);
  DialogForm.Position:= TPosition.poMainFormCenter;
  DialogForm.SetBounds(100, 100, 254, 116);
  DialogForm.Caption:= 'Please, wait...';
  DialogForm.AlphaBlendValue := 230; // 0..255
  DialogForm.AlphaBlend := True;
  DialogForm.BorderStyle:= TFormBorderStyle.bsDialog;

  MyTimer := TTimer.Create(DialogForm);
  MyTimer.Interval := 500;
  MyTimer.OnTimer := @OnTimerEvent;
  MyTimer.Enabled := true;

  //
end;

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version