Recent

Author Topic: Messagebox, text initialy not visible (Linux) till resized  (Read 2882 times)

han

  • Jr. Member
  • **
  • Posts: 96
I have a large application which works fine under MSwindows version. However when converted to Linux, the messagebox's used in the program (in 4 out 5 cases) don't show the text. Only when I resize them larger a few mm by pulling the bottom line down, the text  and the buttons suddenly become visible. Even a simple messagebox instruction like below doesn't display properly:

Application.MessageBox('This is a text of the messagebox', 'Testbox', MB_ICONHAND);

The same thing sometimes happens with a dialog window. Grey till I pull the bottom line down.

If I build a small application, all messageboxes work but not in the larger application. An other Linux (Triquel & Zorin), version did not help.

Any idea how to fix this? :(

Later, the same happens using with "showmessage"  Just a grey window. Resize for this type not possible so text stays fully hidden. Must be common cause???
Later, this only happens when the dialog is placed/called from an "ONPAINT"event of the main form.

« Last Edit: May 27, 2016, 04:02:46 pm by han »

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Messagebox, text initialy not visible (Linux) till resized
« Reply #1 on: May 27, 2016, 04:01:54 pm »
Welcome to Lazarus/FPC forum.

We would like to help you. But because of lack of information, no one will be able to help you. What is the OS, version of the OS, screenshot. And it will be better if source code is provided, you know bug can hide in anywhere in the code.

han

  • Jr. Member
  • **
  • Posts: 96
Re: Messagebox, text initialy not visible (Linux) till resized
« Reply #2 on: May 27, 2016, 04:25:19 pm »
I have attached a test program. I already noticed it only happens when the showmessage or messagebox is placed in the event "ONPAINT of the main form. In any other place the messagebox works correctly.

In mswindows this was never an problem. I use Trisquel (Ubuntu), i386, Lazarus 1.7 GTK2,  FPC3.1.1

« Last Edit: May 27, 2016, 04:29:48 pm by han »

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Messagebox, text initialy not visible (Linux) till resized
« Reply #3 on: May 27, 2016, 04:42:22 pm »
I run the code you provided. I saw a problem. The first time it started, the messagebox is blank, but if I close it and click the button, the messagebox can show correctly. Is it the problem that you mean?

Is yes, then I know why.

Similar to your case, someone asked the question in this forum some weeks ago. For your case, my suggestion is:
Never put any messagebox, showmessage, etc on OnPaint event.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Messagebox, text initialy not visible (Linux) till resized
« Reply #4 on: May 27, 2016, 05:04:29 pm »
Tested again but by moving the things inside OnPaint to OnShow, and it works correctly on my Ubuntu Mate.

Question: Why?

I don't know how to explain, perhaps someone more experience can provide better explanation. I just feel the code should not put on OnPaint. Some weeks ago, there is a question why ShowMessage can't be put on OnCreate.

ShowMessage and MessageBox, and similar things are command that performing painting on the screen it should only be called after the program 'completely' loaded. So it should not be called on TForm.OnCreate nor TForm.OnPaint.

But why not on OnPaint but yes on OnShow?
 :-[ I don't know how to answer, but I have a strong feeling they should be put on OnShow.

han

  • Jr. Member
  • **
  • Posts: 96
Re: Messagebox, text initialy not visible (Linux) till resized
« Reply #5 on: May 27, 2016, 05:17:19 pm »
Thanks for the idea's. Glad you confirmed this behaviour.

Yes it works on "Onshow". The only disadvantage is that my "new user" message is displayed while the main form is not yet visible which is not a good introduction for a "new user" message. So I will probably link it to a "Onkeydown & OnmouseDown event.

Thanks , I can live with this conclusion.  :)


JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Messagebox, text initialy not visible (Linux) till resized
« Reply #6 on: May 27, 2016, 06:19:02 pm »
TForm.OnPaint is supposed to draw on canvas, nothing else.
Opening a message box which steels focus there is begging for trouble (as you noticed).

Yes it works on "Onshow". The only disadvantage is that my "new user" message is displayed while the main form is not yet visible which is not a good introduction for a "new user" message. So I will probably link it to a "Onkeydown & OnmouseDown event.

A typical way to solve that is a timer or, even better, an OnIdle handler which runs immediately after the form is shown and CPU goes idle.
Register it in OnCreate or in OnShow and unregister in the handler itself.
Lazarus IDE's code has plenty of examples about using OnIdle. Slow GUI updates are often done in an OnIdle handler.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018