Lazarus

Programming => General => Topic started by: Ecsa on January 25, 2023, 05:36:10 pm

Title: Controls inside the form disappear in execution.
Post by: Ecsa on January 25, 2023, 05:36:10 pm
Hello, I have had a problem for months that I cannot solve and it is the following.

I create a new project in lazarus version 2.2.4 32 bits on my pc with Windows pro 64 bits, in which I have a simple form to which I add a groupbox, two buttons, a combobox, a progress bar and a listview all these inside the groupbox everything is perfect when it comes to displaying when I execute this form, but I have the problem that when I click inside the form in any location and then with the mouse I click on the Windows taskbar, all the elements They disappear from my form, so to be able to see the components again I have to minimize and then restore the application and everything looks normal, but it's something very annoying and I don't know what I should do to prevent this from happening, it happens with any form and I have tried on several computers and always the same error, does anyone know of a possible solution, I am attaching illustrative images to better understand the problem, thank you very much for your answers in advance.

image GIF: https://imgur.com/e1vsfKR

Video MP4: https://www.mediafire.com/file/i69oiaa2fz11ayr/tloQCeRHbE.mp4/file
Title: Re: Controls inside the form disappear in execution.
Post by: KodeZwerg on January 25, 2023, 05:47:15 pm
Can you attach a small demo project please? I just tried (I only got 64bit compiler) and there I do not have this kind of effect showing. Maybe it is something different ...
Title: Re: Controls inside the form disappear in execution.
Post by: Ecsa on January 25, 2023, 05:55:33 pm
I already attached the project, and this happens to me with all the projects that I am going to create, sometimes you have to click several times on the form and then outside of it, as in this case on the taskbar or even to check the icons hidden in the Windows system tray. It doesn't always come out the first time it's clicked, I'm going to upload a video to show the error.

image GIF: https://imgur.com/e1vsfKR
Title: Re: Controls inside the form disappear in execution.
Post by: WooBean on January 25, 2023, 06:43:16 pm
Hi, Ecsa

I tried your test project on win 7/64 pro, Lazarus 2.2.0, FPC 3.2.2 for both targets - win64 and win32 - it seems there is no problem. Nothing strange  (as you described) happened to me.

Your months of an unsuccesful fight sound alarming.
My suggestions - check Lazarus installations, viruses, hardware. May be it is better to use 64 bit installation of Lazarus with support of 32 bit target? (Needed downloading and installing cross-compiller lazarus-2.2.4-fpc-3.2.2-cross-i386-win32-win64.exe). 
Title: Re: Controls inside the form disappear in execution.
Post by: KodeZwerg on January 25, 2023, 06:55:56 pm
Lazarus 2.2.4 (rev lazarus_2_2_4) FPC 3.2.2 x86_64-win64-win32/win64

I've run and tested, strange thing is, when I build on my own, all works like it should, importing and running your demo shows me same behaviour.
It seems like, when "TGroupBox" is the only control on form, something shitty happen at repaint/refresh/update.

First thing I've changed was to put a panel inside the GB with alClient and moved all of your controls on it. That reduced the error but not stopped it.
Second, I've put a panel alClient on form on moved GB alClient inside. That reduced the error but not stopped it.
Third, I've put another panel alBottom on form (outside of above panel/GB). That almost reduced the error to zero but not stopped it.

I am clueless what there is going on. I try to investigate that deeper. To me it look like a bug.
Title: Re: Controls inside the form disappear in execution.
Post by: wp on January 25, 2023, 07:07:23 pm
Unlike KodeZwerg I cannot reproduce the issue on Win-11 neither with Laz 2.2.4/FPC 3.2.2/64 bit nor 32-bit nor with Laz main/FPC 3.2.2 32bit.

Yes, anti-virus is always a good candidate to explain something unsual happening. Put your Lazarus installation directory as well as your project directory(directories) on the white-list of the virus scanner. Turn off anti-virus for a test. If this fixes the issue send a report to the provider of the antivirus application.

The next candidates are third-party packages. Since installed packages are linked into the IDE they can cause malfunction of the IDE. Find out the directory in which your user settings are stored: Go to "View" > "IDE Internals" > "About IDE"; in the second paragraph (under "Global IDE Options") read the "primary config directory" items and write down the path. Close Lazarus. In the Windows Explorer, go to this path and rename it. Restart the IDE - this will write default user settings, without installed packages. Go to "Tools" > "Configure Build Lazarus" and check "Clean all" and "Switch after building to automatically", then click "Build". This rebuilds a new ID, without your packages. Repeat your tests with simple projects (which do not require the packages). If the issue is gone install your packages one by one and repeat the tests again so that you find out which packages is causing the trouble. Contact the author of the package and tell him about the issue caused by his package (or drop a note here in the forum).

Do you use the docked user interface (anchor docking)? There are many reports about issues caused by this package.

If you are still unsuccessful the easiest way is to reinstall Lazarus. Choose a "secondary installation" in the installer; this keeps the new installation separate from your old installation. You must specify a directory for your user settings here on some page of the installer. And you should not associate file types with Windows because when you have several Lazarus installations you never know which version opens upon a double-click.
Title: Re: Controls inside the form disappear in execution.
Post by: KodeZwerg on January 25, 2023, 07:25:29 pm
My current only work-around, quick and dirty:
Code: Pascal  [Select][+][-]
  1.   TForm1 = class(TForm)
  2.     procedure DoFix(Sender: TObject);
  3.     procedure FormCreate(Sender: TObject);
  4.   private
  5.   public
  6.   end;
  7.  
  8. implementation
  9.  
  10. procedure TForm1.FormCreate(Sender: TObject);
  11. begin
  12.   Application.OnActivate := @DoFix;
  13.   Application.OnDeactivate := @DoFix;
  14. end;
  15.  
  16. procedure TForm1.DoFix(Sender: TObject);
  17. var
  18.   i: Integer;
  19. begin
  20.   for i := 0 to Pred(ControlCount) do
  21.     begin
  22.       // one of them fixes the disappearing...
  23.       TControl(Controls[i]).Refresh;
  24.       TControl(Controls[i]).Repaint;
  25.       TControl(Controls[i]).Update;
  26.     end;
  27. end;
Title: Re: Controls inside the form disappear in execution.
Post by: Ecsa on January 25, 2023, 07:39:45 pm
Hi, Ecsa

I tried your test project on win 7/64 pro, Lazarus 2.2.0, FPC 3.2.2 for both targets - win64 and win32 - it seems there is no problem. Nothing strange  (as you described) happened to me.

Your months of an unsuccesful fight sound alarming.
My suggestions - check Lazarus installations, viruses, hardware. May be it is better to use 64 bit installation of Lazarus with support of 32 bit target? (Needed downloading and installing cross-compiller lazarus-2.2.4-fpc-3.2.2-cross-i386-win32-win64.exe).

I have tried in a clean installation of windows and also with recently installed lazarus without adding any new package, everything by default when creating the project and this happens in all versions of Windows from 7 to 11 (non-virtualized physical machines) where I have seen the same mistake. And of course it can be an error as mentioned.
Title: Re: Controls inside the form disappear in execution.
Post by: Ecsa on January 25, 2023, 07:40:29 pm
My current only work-around, quick and dirty:
Code: Pascal  [Select][+][-]
  1.   TForm1 = class(TForm)
  2.     procedure DoFix(Sender: TObject);
  3.     procedure FormCreate(Sender: TObject);
  4.   private
  5.   public
  6.   end;
  7.  
  8. implementation
  9.  
  10. procedure TForm1.FormCreate(Sender: TObject);
  11. begin
  12.   Application.OnActivate := @DoFix;
  13.   Application.OnDeactivate := @DoFix;
  14. end;
  15.  
  16. procedure TForm1.DoFix(Sender: TObject);
  17. var
  18.   i: Integer;
  19. begin
  20.   for i := 0 to Pred(ControlCount) do
  21.     begin
  22.       // one of them fixes the disappearing...
  23.       TControl(Controls[i]).Refresh;
  24.       TControl(Controls[i]).Repaint;
  25.       TControl(Controls[i]).Update;
  26.     end;
  27. end;

Thank you, I will review and apply it to other projects to see if this detail can be avoided in this way.
Title: Re: Controls inside the form disappear in execution.
Post by: KodeZwerg on January 25, 2023, 07:44:09 pm
Buena suerte y de nada // Good luck and you're welcome
Title: Re: Controls inside the form disappear in execution.
Post by: KodeZwerg on January 25, 2023, 07:59:51 pm
After more testing, Refresh <or> Repaint is enough, Update you can delete out. I suggest to stick with Refresh, works best for me.
But as every medal has two sides, on one side it really does fix that disappearing on the other side you will see for a micro second a flicker on form, I am sorry.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DoFix(Sender: TObject);
  2. var
  3.   i: Integer;
  4. begin
  5.   for i := 0 to Pred(ControlCount) do
  6.     TControl(Controls[i]).Refresh;
  7. end;
Title: Re: Controls inside the form disappear in execution.
Post by: wp on January 25, 2023, 08:05:31 pm
Still, I would like to understand why I am not seeing this. Are you using anchordocking?
Title: Re: Controls inside the form disappear in execution.
Post by: dsiders on January 25, 2023, 08:13:19 pm
Still, I would like to understand why I am not seeing this. Are you using anchordocking?

I use AnchorDocking/DockedFormEditor, and I do not see this behavior in 2.2.4 or 2.3.0.
Title: Re: Controls inside the form disappear in execution.
Post by: KodeZwerg on January 25, 2023, 08:13:46 pm
Still, I would like to understand why I am not seeing this. Are you using anchordocking?
I tried with a full installation of my Lazarus, lots of Components from OPM added also AnchorDocking. How can that have an impact for running an compiled executable?
I am sorry, for myself I can not put another "clean" Lazarus installation on my system to test, I just can try to find out what happen, give me more time please.
All I can say, something shitty happen in Application.On(de)Activate, in both original events the controls random disappear (in demo the only control that is not affected is the progressbar)
Title: Re: Controls inside the form disappear in execution.
Post by: WooBean on January 25, 2023, 08:15:40 pm
Still, I would like to understand why I am not seeing this. Are you using anchordocking?

Well, my trials were from docked IDE, Lazarus 2.2.0, FPC 3.2.2, Win7pro/64 and no errors occured.
BTW, on Linux 64, gtk2, Lazarus 2.2.0, IDE docked, a form looks a little ugly but works as should (no hidden controls).   
Title: Re: Controls inside the form disappear in execution.
Post by: tetrastes on January 25, 2023, 08:18:57 pm
The issue is reproduced at my Win10 Laz 2.2.4 fpc 3.2.2.
I have discovered that it is linked with DoubleBuffered somehow, maybe because TListView and TProgressBar have not DoubleBuffered property.
I have set GroupBox1 DoubleBuffered property to False, and the issue goes away.
Title: Re: Controls inside the form disappear in execution.
Post by: KodeZwerg on January 25, 2023, 08:23:25 pm
The issue is reproduced at my Win10 Laz 2.2.4 fpc 3.2.2.
I have discovered that it is linked with DoubleBuffered somehow, maybe because TListView and TProgressBar have not DoubleBuffered property.
I have set GroupBox1 DoubleBuffered property to False, and the issue goes away.
That I also tried, keep doing activate/deactivate the window and you see the error again. At least there is another person that can confirm that strange behaviour.
Title: Re: Controls inside the form disappear in execution.
Post by: tetrastes on January 25, 2023, 08:51:12 pm
I believe it willingly, but I don't have enough patience...
Title: Re: Controls inside the form disappear in execution.
Post by: Ecsa on January 25, 2023, 09:00:19 pm
Buena suerte y de nada // Good luck and you're welcome
I just applied it to another form from another project and the same problem doesn't work, I'm going to remove the groupbox so I don't see that bug, anyway, thank you very much for your support.  :'(
Title: Re: Controls inside the form disappear in execution.
Post by: Ecsa on January 25, 2023, 09:05:41 pm
The issue is reproduced at my Win10 Laz 2.2.4 fpc 3.2.2.
I have discovered that it is linked with DoubleBuffered somehow, maybe because TListView and TProgressBar have not DoubleBuffered property.
I have set GroupBox1 DoubleBuffered property to False, and the issue goes away.

I just set DoubleBuffered to false and I get the same problem, the controls disappear that if I have to do the process of clicking on the form multiple times, then click outside the form (Windows taskbar.)
Title: Re: Controls inside the form disappear in execution.
Post by: KodeZwerg on January 25, 2023, 09:34:50 pm
Buena suerte y de nada // Good luck and you're welcome
I just applied it to another form from another project and the same problem doesn't work, I'm going to remove the groupbox so I don't see that bug, anyway, thank you very much for your support.  :'(
I am sorry that my fix did not worked on your other projects  :'( I tried best to help  :-[
Title: Re: Controls inside the form disappear in execution.
Post by: Thaddy on January 25, 2023, 09:37:00 pm
It is likely that, that the control that you assume to contain other controls did not have focus at the time you added the other controls.

Example: when you want to put controls on a panel, make sure the panel has focus (the squares around the corners and the middles) before you add the controls visually. Otherwise the owner becomes the form itself, and not the panel and that may hide the controls. (same goes for Delphi, but Delphi behaves a bit better than Lazarus that can mix-up order quite easily: meaning last added control does not have the same z-order as you would expect (LIFO), so in Delphi it mostly "looks" OK, but it isn't either: same programmer mistake).
This is a "pitfall" for screendrawers sorry, beginners, but not usually for programmers.
You can test that while debugging by testing the parent control. If that is the form and not the panel... then you have the issue as I described above.
Title: Re: Controls inside the form disappear in execution.
Post by: tetrastes on January 25, 2023, 10:11:30 pm
You can test that while debugging by testing the parent control. If that is the form and not the panel... then you have the issue as I described above.
This is not the case. The parent of all controls is GroupBox1, what you can easily see in Object Inspector.
By the way, I don't have this issue with TPanel, only with TGroupBox.
Title: Re: Controls inside the form disappear in execution.
Post by: Ecsa on January 25, 2023, 10:20:40 pm
It is likely that, that the control that you assume to contain other controls did not have focus at the time you added the other controls.

Example: when you want to put controls on a panel, make sure the panel has focus (the squares around the corners and the middles) before you add the controls visually. Otherwise the owner becomes the form itself, and not the panel and that may hide the controls. (same goes for Delphi, but Delphi behaves a bit better than Lazarus that can mix-up order quite easily: meaning last added control does not have the same z-order as you would expect (LIFO), so in Delphi it mostly "looks" OK, but it isn't either: same programmer mistake).
This is a "pitfall" for screendrawers sorry, beginners, but not usually for programmers.
You can test that while debugging by testing the parent control. If that is the form and not the panel... then you have the issue as I described above.

Understanding that when adding a control I must have the main control selected, as in this case it is a groupbox, for which I create another project and make sure that the groupbox is in focus to add the new control and the same thing happens when clicking inside the groupbox control and then outside the form window hides all the controls.
Title: Re: Controls inside the form disappear in execution.
Post by: jamie on January 25, 2023, 10:51:02 pm
Application.ProcessMessages in the OnDeactivate event?
Title: Re: Controls inside the form disappear in execution.
Post by: KodeZwerg on January 25, 2023, 11:47:16 pm
Application.ProcessMessages in the OnDeactivate event?
Sadly not.
First Image = How it really should look
Second = after a few times de-/activate the window
Third = shows the code

For me just my disabled "fix" (also visible on third image) is working and currently I do not understand why that is not working for Ecsa.
Title: Re: Controls inside the form disappear in execution.
Post by: 440bx on January 26, 2023, 03:06:18 am
I've run and tested, strange thing is, when I build on my own, all works like it should,
Same here.


importing and running your demo shows me same behaviour.
I don't understand this part.  Importing what and running what ?... his zip file does not contain an executable (at least not the one I downloaded.)  How did you run "his demo" (presuming you mean "his executable" an executable _he_, not you, created ?.)  What am I missing ?

One test I'd like to see done is, for the OP to provide an executable that exhibits the problem on his system(s).  I'd like someone with the same version of Windows, FPC and Lazarus as the OP to produce an executable.

It would be very interesting to see, if those two _expected to be identical executables_, behave the same way or differently on the OP's system as well as forum member's systems.

Title: Re: Controls inside the form disappear in execution.
Post by: wp on January 26, 2023, 10:01:11 am
Could those who see this issue tell us the exact operating system they are using? Couldn't it be that this is due to one of the many bugs introduced by Microsoft after Win 7 and which are now gradually removed?

Mine is Win-11 Home (64 bit) Version 22H2, Build 22621.1105, and I also have a Win-7 Pro Service Pack 1 (32 bit) on a VM. None of them shows the issue.
Title: Re: Controls inside the form disappear in execution.
Post by: tetrastes on January 26, 2023, 10:06:26 am
Could those who see this issue tell us the exact operating system they are using? Couldn't it be that this is due to one of the many bugs introduced by Microsoft after Win 7 and which are now gradually removed?

Mine is Win-11 Home (64 bit) Version 22H2, Build 22621.1105, and I also have a Win-7 Pro Service Pack 1 (32 bit) on a VM. None of them shows the issue.

Win-10 Home (64 bit) Version 22H2, Build 19045.2486
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 26, 2023, 10:13:00 am
Could those who see this issue tell us the exact operating system they are using? Couldn't it be that this is due to one of the many bugs introduced by Microsoft after Win 7 and which are now gradually removed?

Mine is Win-11 Home (64 bit) Version 22H2, Build 22621.1105, and I also have a Win-7 Pro Service Pack 1 (32 bit) on a VM. None of them shows the issue.
I can reproduce the issue with every Lazarus/FPC version I have, both on win10 and win11. The issue is more serious then I thought: TGroupBox, TRadioGroup, TCheckBox are all affected. It's related to the DoubleBuffered property, as mentioned in one of the previous posts. If I set DoubleBuffered to False the issue is gone.
Step to reproduce:
1. Drop a TGroupBox to a from
2. Make sure Doubebuffered is true
3. Drop random controls inside TGroupBox
4. Run application
5. Click ten times or so inside the TGroupBox
6. Click a few times the taskbar. It will only work if you click the taskbar, the empty part of the taskbar
7. Click the TGroupBox again
Repeat 5 -> 7 until you see the issue.

PS: Similar application created with delphi don't show this behaviour.
PS: I will soon test it on win7....the issue is present on win7 too.
Title: Re: Controls inside the form disappear in execution.
Post by: wp on January 26, 2023, 10:40:32 am
5. Click ten times or so inside the TGroupBox
"inside the TGroupBox" - does this mean: "on the controls" or "somewhere, but not on the controls"?
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 26, 2023, 10:48:59 am
5. Click ten times or so inside the TGroupBox
"inside the TGroupBox" - does this mean: "on the controls" or "somewhere, but not on the controls"?
Somewhere, but not on the controls.
Title: Re: Controls inside the form disappear in execution.
Post by: tetrastes on January 26, 2023, 10:58:06 am
6. Click a few times the taskbar. It will only work if you click the taskbar, the empty part of the taskbar

If I create a shortcut to a program on the desktop and launch it from the shortcut, this behavior is also displayed when clicking on an empty space on the desktop.
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 26, 2023, 11:05:58 am
6. Click a few times the taskbar. It will only work if you click the taskbar, the empty part of the taskbar

If I create a shortcut to a program on the desktop and launch it from the shortcut, this behavior is also displayed when clicking on an empty space on the desktop.
OK, good to know. Thanks!
Title: Re: Controls inside the form disappear in execution.
Post by: wp on January 26, 2023, 11:08:22 am
OK, now I can reproduce it (Win11, Laz/main+fpc3.2.2 (32bit), Laz 2.2.4+fpc3.2.2 (64bit), Laz 2.0.12+fpc3.2.0, Laz 1.8.4+fpc3.0.2, Laz 1.4.4+fpc 2.6.4)

I click the same spot of the groupbox not covered by a control about 10 times, then click on an empty spot in the taskbar, and the controls in the groupbox disappear (the groupbox border remains). A click back into the groupbox is not necessary.

In the Laz versions older than 2.0, the DoubleBuffered propery is not published and is off by default. But in the default state, and when I activate it in FormCreate, I get the same behaviour essentially, but now the areas in the groupbox covered by the controls are painted as black rectangles. When i move the mouse over these areas (without any button pressed) the controls re-appear. This happens also in the newer versions in which the black rectangles do not appear.
Title: Re: Controls inside the form disappear in execution.
Post by: KodeZwerg on January 26, 2023, 11:09:07 am
If I set DoubleBuffered to False the issue is gone.
Sadly not. Just de-/activate window more often and you get same issue.
I turned DoubleBuffer to False for everything = issue is there.
(...With my fix it is gone...)
Title: Re: Controls inside the form disappear in execution.
Post by: tetrastes on January 26, 2023, 12:27:42 pm
If I set DoubleBuffered to False the issue is gone.
Sadly not. Just de-/activate window more often and you get same issue.
I turned DoubleBuffer to False for everything = issue is there.
(...With my fix it is gone...)

Try
Code: Pascal  [Select][+][-]
  1. Application.DoubleBuffered := adbFalse;    // Add this
  2. Application.Initialize;

and set ParentDoubleBuffered to True for everything.
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 26, 2023, 01:45:29 pm
Good! Then everyone is able to reproduce it.
It looks like WM_Paint issue. Just to prove it, I made a low level mouse hook(attachment1), when the taskbar is clicked, the GroupBox is repainted by force. With this workaround the issue is gone, however this is not a solution.

PS: Apparently we are not the only ones who bumped into this bug(attachment 2).
Title: Re: Controls inside the form disappear in execution.
Post by: wp on January 26, 2023, 03:11:13 pm
when the taskbar is clicked[...]
It's not only the taskbar. It happens also when I click into an IDE form rather than the taskbar.
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 26, 2023, 03:28:09 pm
when the taskbar is clicked[...]
It's not only the taskbar. It happens also when I click into an IDE form rather than the taskbar.
Sure, it's not about the taskbar. With my demo project, I only wanted to prove that is a repaint issue.
If somebody wants to take a look, the painting process is in: lazarus\lcl\include\wincontrol.inc, but be prepared to get dizzy.
Title: Re: Controls inside the form disappear in execution.
Post by: jamie on January 27, 2023, 01:39:43 am
Can someone drop a TComboBox on the form using csSIMPLE style and stretch it out vertically and add some items.

 conduct the test you have been doing to see if that also disappears?
Title: Re: Controls inside the form disappear in execution.
Post by: Ecsa on January 27, 2023, 04:02:37 am
Hello and thank you all for your help, as I mentioned in some messages I have the problem from Windows 7 to Windows 11 updated to the latest build and in all of them there is the problem that the controls disappear and to make them appear you have to pass the mouse over them controls but they all look horrible or minimize and restore the form window, it's kind of annoying, with the solution that they gave me at the beginning for the project that I shared if it worked for a moment but the problem is there. Hopefully some developer in charge of lazarus will come to see this problem and fix it in a future update.

And if it is not necessarily clicking on the taskbar and it even happens if another window is placed in the foreground then when minimizing to see the form the problem occurs.
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 28, 2023, 05:28:24 am
@jamie
Quote
Can someone drop a TComboBox on the form using csSIMPLE style and stretch it out vertically and add some items.
The issue is visible with or without a TComboBox. Style, align does not matter.
Title: Re: Controls inside the form disappear in execution.
Post by: jamie on January 28, 2023, 04:40:32 pm
a little testing here.

 How is it a TGroupbox with nothing in it, receives a LM_KILLFOCUS when you click on it?

 For which the message handler simply calls the EXIT this not passing it onto the inherited winProc.

Title: Re: Controls inside the form disappear in execution.
Post by: jamie on January 28, 2023, 05:53:22 pm

 This is what i did and for the simple test app the @GetMem posted after I commented out this invalidate within.

In the WinControl.inc file I inserted a "Invalidate" in the LM_KILLFOCUS message.

Code: Pascal  [Select][+][-]
  1.     LM_KILLFOCUS:
  2.       begin
  3.         //DebugLn(Format('Trace:[TWinControl.WndPRoc] %s --> _KILLFOCUS', [ClassName]));
  4.         if csFocusing in ControlState then
  5.         begin
  6.           {$IFDEF VerboseFocus}
  7.           DebugLn('TWinControl.WndProc LM_KillFocus during focusing ',Name,':',ClassName);
  8.           {$ENDIF}
  9.           Exit;
  10.         end;
  11.         Invalidate;//<<< added JP.
  12.         Message.Result:=0;
  13.       end;                  
  14.  

This is in the TWinControl.WindProc....

 Here is seems to work well.

Maybe others can fully test this with complete apps.

Title: Re: Controls inside the form disappear in execution.
Post by: tetrastes on January 28, 2023, 07:45:04 pm
Thank you, jamie, it works. But when there are many child controls, redrawing is noticeable...
Title: Re: Controls inside the form disappear in execution.
Post by: jamie on January 28, 2023, 08:59:08 pm
Always or just switching the complete form out of scope?



Title: Re: Controls inside the form disappear in execution.
Post by: tetrastes on January 28, 2023, 09:14:04 pm
Switching the complete form out of scope.
Title: Re: Controls inside the form disappear in execution.
Post by: jamie on January 28, 2023, 09:23:40 pm
Ok, I don't think there much about that can done about that, unless someone wants to narrow is down to only take place with a Groupbox but I think that would be stupid.
Title: Re: Controls inside the form disappear in execution.
Post by: jamie on January 28, 2023, 11:19:59 pm
Ok, I have added a message to the GroupBox message handler.
In file "Win32WSStdCtrls"
Code: Pascal  [Select][+][-]
  1. function GroupBoxWindowProc(Window: HWnd; Msg: UInt; WParam: Windows.WParam;
  2.     LParam: Windows.LParam): LResult; stdcall;
  3. var
  4.   Info: PWin32WindowInfo;
  5.   DC: HDC;
  6.   Flags: Cardinal;
  7.   ARect: TRect;
  8.   WideBuffer: WideString;
  9.   GroupBox: TCustomGroupBox;
  10. begin
  11.   // move groupbox specific code here
  12.   case Msg of
  13.     WM_NCHITTEST:
  14.       begin
  15.         Result := HTCLIENT;
  16.         Exit;
  17.       end;
  18.     WM_ENABLE:
  19.       begin
  20.         Result := WindowProc(Window, Msg, WParam, LParam);
  21.         // if it is groupbox and themed app then invalidate it on enable change
  22.         // to redraw graphic controls on it (issue 0007877)
  23.         if ThemeServices.ThemesAvailable then
  24.           InvalidateRect(Window, nil, True);
  25.          Exit;
  26.       end;
  27.     WM_KILLFOCUS: InvalidateRect(Window,Nil,false);//Jp;
  28.     WM_PAINT:                                  
  29.  

There seems to be a Focus issue with the group box, personnaly, I didn't know a group box received focus.?
 Please try that where "Jp" is marked in comments, just insert that message handler.

EDIT:
 I just noticed that also, there is a problem with WM_SETFOCUS.
 basically the same thing happens if the Groupbox was in focus and then you restore it from another form. So I think the WM_ SETFOCUS will also be required in this addition.
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 29, 2023, 06:32:14 pm
@jamie
Your changes definitely helps. I also see flickering, but it's much better then controls disappearing.
Title: Re: Controls inside the form disappear in execution.
Post by: jamie on January 29, 2023, 06:52:22 pm
Well, until someone can explain why the groupbox is allowed to receive focus which delphi apparently doesn't do, I guess I can finalize my changes to the local copies and call it a day.

 Btw, it is the groupbox getting focus which is causing the issue.

 Maybe base LCL should not allow this because in the end, you cannot capture the keystrokes from any Wincontrol that may have focus within the groupbox.


Title: Re: Controls inside the form disappear in execution.
Post by: jamie on January 29, 2023, 07:34:42 pm
It seems if though if I simply block those messages from being processed it works fine?

I also noticed the TAB operation seems to be funky, but it does not matter either way you alter the code, tabbing seems to be another abnormally.

So doing this instead of InvalidateRect...

 WM_KILLFOCUS,WM_SETFOCUS: Exit;

DO that in the same area instead and try that, it appears everything is working!?

I have not found any side effects doing this so this I will finalize instead. It seems to work.

Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 30, 2023, 07:45:54 am
It seems if though if I simply block those messages from being processed it works fine?

I also noticed the TAB operation seems to be funky, but it does not matter either way you alter the code, tabbing seems to be another abnormally.

So doing this instead of InvalidateRect...

 WM_KILLFOCUS,WM_SETFOCUS: Exit;

DO that in the same area instead and try that, it appears everything is working!?

I have not found any side effects doing this so this I will finalize instead. It seems to work.
Apparently that solves the issue, I don't see any side effects either. However modifying LCL is always tricky, needs thorough testing before it can be applied in main.

@all
Please test @jamie's changes.
Title: Re: Controls inside the form disappear in execution.
Post by: dsiders on January 30, 2023, 08:22:51 am
It seems if though if I simply block those messages from being processed it works fine?

I also noticed the TAB operation seems to be funky, but it does not matter either way you alter the code, tabbing seems to be another abnormally.

So doing this instead of InvalidateRect...

 WM_KILLFOCUS,WM_SETFOCUS: Exit;

DO that in the same area instead and try that, it appears everything is working!?

I have not found any side effects doing this so this I will finalize instead. It seems to work.
Apparently that solves the issue, I don't see any side effects either. However modifying LCL is always tricky, needs thorough testing before it can be applied in main.

@all
Please test @jamie's changes.

I would gladly test... but using what? The original test.zip for post #1 I assume. Is there a patch or diff with the changes that need to be applied to perform the testing?
Title: Re: Controls inside the form disappear in execution.
Post by: Mr.Madguy on January 30, 2023, 08:36:20 am
It seems if though if I simply block those messages from being processed it works fine?

I also noticed the TAB operation seems to be funky, but it does not matter either way you alter the code, tabbing seems to be another abnormally.

So doing this instead of InvalidateRect...

 WM_KILLFOCUS,WM_SETFOCUS: Exit;

DO that in the same area instead and try that, it appears everything is working!?

I have not found any side effects doing this so this I will finalize instead. It seems to work.
Only difference - if WindowProc is called and what result it returns.
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 30, 2023, 10:02:17 am
@dsiders

Quote
I would gladly test... but using what? The original test.zip for post #1 I assume. Is there a patch or diff with the changes that need to be applied to perform the testing?
1. Download, extract then run attached project
2. Click ten times or so inside the TGroupBox, without clicking another control
3. Click a few times the taskbar(the empty part of the taskbar)
4. Click the TGroupBox again
Repeat 2 -> 4 until you see the issue. As mentioned before, there are other ways to reproduce the bug, but I found the above method the easiest.

Once you see the issue:
1. Open: $(LazarusDir)\lcl\interfaces\win32\Win32WSStdCtrls.pp
2. Go to function GroupBoxWindowProc
3. Add the following lines, just before WM_PAINT:
Code: Pascal  [Select][+][-]
  1.  WM_KILLFOCUS, WM_SETFOCUS:
  2.     Exit;
  3.  
4. Rebuild IDE

The issue should be gone, hopefully without side effects.
Title: Re: Controls inside the form disappear in execution.
Post by: Mr.Madguy on January 30, 2023, 10:32:41 am
The issue should be gone, hopefully without side effects.
Where can I find contents of GroupBox's WindowProc? I guess, DefWindowProc should be called for these messages. It is possible, that WindowProc overrides this behavior. Even if it just returns wrong result. Remember, that in most cases 0 result means processing message by application.
Title: Re: Controls inside the form disappear in execution.
Post by: tetrastes on January 30, 2023, 10:54:14 am
1. Open: $(LazarusDir)\lcl\interfaces\win32\Win32WSStdCtrls.pp
2. Go to function GroupBoxWindowProc
3. Add the following lines, just before WM_PAINT:
Code: Pascal  [Select][+][-]
  1.  WM_KILLFOCUS, WM_SETFOCUS:
  2.     Exit;
  3.  
4. Rebuild IDE

The issue should be gone, hopefully without side effects.

I am not sure in that also, as Mr.Madguy. GroupBoxWindowProc must return something. What does it return in this case?
Maybe do something like this:
Code: Pascal  [Select][+][-]
  1.     WM_NCHITTEST:
  2.       begin
  3.         Result := HTCLIENT;
  4.         Exit;
  5.       end;
  6.  
?
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 30, 2023, 11:22:14 am
@Mr.Madguy
Quote
Where can I find contents of GroupBox's WindowProc?
$(LazarusDir)\lcl\interfaces\win32\Win32WSStdCtrls.pp


@Mr.Madguy,
Quote
I guess, DefWindowProc should be called for these messages. It is possible, that WindowProc overrides this behavior. Even if it just returns wrong result. Remember, that in most cases 0 result means processing message by application.
@tetrastes
Quote
I am not sure in that also, as Mr.Madguy. GroupBoxWindowProc must return something. What does it return in this case?

If I add CallDefaultWindowProc the issue is back:
Code: Pascal  [Select][+][-]
  1.   WM_KILLFOCUS, WM_SETFOCUS:
  2.     begin
  3.       CallDefaultWindowProc(Window, Msg, WParam, LParam);
  4.       Exit;
  5.     end;    
         
The idea is that TGroupBox should not receive message WM_SETFOCUS, WM_KILLFOCUS. I see similar solution in D. sources too, no DefWindowProc is called after WM_KILLFOCUS, just Exit;
This also works:
Code: Pascal  [Select][+][-]
  1.   WM_KILLFOCUS, WM_SETFOCUS:
  2.     begin
  3.        Result := 0;
  4.        Exit;
  5.     end;    

Title: Re: Controls inside the form disappear in execution.
Post by: Mr.Madguy on January 30, 2023, 12:33:45 pm
$(LazarusDir)\lcl\interfaces\win32\Win32WSStdCtrls.pp
No, GroupBoxWindowProc calls Result := WindowProc at the end. What is called? Things are hard to track in WS classes.
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 30, 2023, 12:45:02 pm
$(LazarusDir)\lcl\interfaces\win32\Win32WSStdCtrls.pp
No, GroupBoxWindowProc calls Result := WindowProc at the end. What is called? Things are hard to track in WS classes.
1. Menu -> Tools -> Configure "Build Lazarus" ..
2. Select Debug Ide, then rebuild IDE
3. Put a breakpoint to(unit Win32WSStdCtrls.pp, function GroupBoxWindowProc):
  Result := WindowProc(Window, Msg, WParam, LParam);
4. When it breaks press F7
Title: Re: Controls inside the form disappear in execution.
Post by: KodeZwerg on January 30, 2023, 02:27:59 pm
I haven't tried your modifications yet but a GroupBox should react to be able that it can receive focus event, in that case the first "focusable" control inside that GB gets it.
Will your way of doing still let Tabulator key works like before?
exemplary put a edit1 on form (TabOrder (TO) = 0), GroupBox (GB) TO = 1, inside GB another edit2 TO = 0, under that GB another edit3 TO = 2
in theory when starting app and edit1 is focused, press TAB and edit2 is focused again TAB and edit3 is focused again TAB and it start from beginning...
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 30, 2023, 02:58:14 pm
I haven't tried your modifications yet but a GroupBox should react to be able that it can receive focus event, in that case the first "focusable" control inside that GB gets it.
Will your way of doing still let Tabulator key works like before?
exemplary put a edit1 on form (TabOrder (TO) = 0), GroupBox (GB) TO = 1, inside GB another edit2 TO = 0, under that GB another edit3 TO = 2
in theory when starting app and edit1 is focused, press TAB and edit2 is focused again TAB and edit3 is focused again TAB and it start from beginning...
Yes, everything works fine. I did not find any anomalies so far.
Title: Re: Controls inside the form disappear in execution.
Post by: wp on January 30, 2023, 03:13:19 pm
Shouldn't we commit it to have a larger test base? If there is an issue with it we could remove the few lines again at any time...

And I think we should have a bugreport for it referring to this discussion to document why this is changed. This makes life much easier if somebody detects a regression some years later...
Title: Re: Controls inside the form disappear in execution.
Post by: dsiders on January 30, 2023, 07:22:05 pm
@dsiders

Quote
I would gladly test... but using what? The original test.zip for post #1 I assume. Is there a patch or diff with the changes that need to be applied to perform the testing?
1. Download, extract then run attached project
2. Click ten times or so inside the TGroupBox, without clicking another control
3. Click a few times the taskbar(the empty part of the taskbar)
4. Click the TGroupBox again
Repeat 2 -> 4 until you see the issue. As mentioned before, there are other ways to reproduce the bug, but I found the above method the easiest.

Once you see the issue:
1. Open: $(LazarusDir)\lcl\interfaces\win32\Win32WSStdCtrls.pp
2. Go to function GroupBoxWindowProc
3. Add the following lines, just before WM_PAINT:
Code: Pascal  [Select][+][-]
  1.  WM_KILLFOCUS, WM_SETFOCUS:
  2.     Exit;
  3.  
4. Rebuild IDE

The issue should be gone, hopefully without side effects.

Thank you. I will try it later today.
Title: Re: Controls inside the form disappear in execution.
Post by: tetrastes on January 30, 2023, 07:33:36 pm
Yes, everything works fine. I did not find any anomalies so far.

I did. I applied this:
Code: Pascal  [Select][+][-]
  1.   WM_KILLFOCUS, WM_SETFOCUS:
  2.     begin
  3.        Result := 0;
  4.        Exit;
  5.     end;    
(it seems more robust for me).

The OP issue went away, but try the following. Mouse click the empty space of GroupBox, press TAB, repeat if needed. Program stops responding to pressing TAB.
Remove WM_SETFOCUS:
Code: Pascal  [Select][+][-]
  1.   WM_KILLFOCUS:
  2.     begin
  3.        Result := 0;
  4.        Exit;
  5.     end;    
it seems that program works fine now.
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 30, 2023, 08:04:09 pm
@tetrastes
Very nicely done! I can confirm that your changes fix the TAB issue.
Quote
It seems that program works fine now.
Please run a few more test. I' m almost certain that we will find more issues. Changing something in LCL is always tricky.

@wp
Quote
Shouldn't we commit it to have a larger test base? If there is an issue with it we could remove the few lines again at any time...
And I think we should have a bugreport for it referring to this discussion to document why this is changed. This makes life much easier if somebody detects a regression some years later...
Not yet, @tetrastes already found a bug. I fully agree with the bugreport.
Title: Re: Controls inside the form disappear in execution.
Post by: tetrastes on January 30, 2023, 08:19:56 pm
Please run a few more test. I' m almost certain that we will find more issues. Changing something in LCL is always tricky.
Unfortunately you are right.

it seems that program works fine now.
I was wrong. Without WM_SETFOCUS the OP issue is reproduced, but not with TaskBar:
1. Start test program
2. Start another program (Lazarus or Explore, maybe some others, but not all) which overlaps the test program.
3. Minimize that another program.
4. Mouse click the empty space of GroupBox of the test program.
5. Restore another program, then minimize it.
6. See the OP issue.  :(

EDIT: Maybe it is reproduced with clicking taskbar also, but I can't. But this method also shows the OP issue at test program with disabled DoubleBuffered, as KodeZwerg wrote, what I can't reproduce by clicking taskbar.
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 30, 2023, 08:39:28 pm
@tetrastes
Please try with this:
Code: Pascal  [Select][+][-]
  1.     WM_SETFOCUS:
  2.       begin
  3.         Result := WindowProc(Window, Msg, WParam, LParam);
  4.         Info := GetWin32WindowInfo(Window);
  5.         if Assigned(Info) and Info^.WinControl.IsEnabled then
  6.           InvalidateRect(Info^.WinControl.Handle, nil, True);
  7.         Exit;
  8.       end;
  9.     WM_KILLFOCUS:
  10.       begin
  11.         Result := 0;
  12.         Exit;
  13.       end;              
Title: Re: Controls inside the form disappear in execution.
Post by: tetrastes on January 30, 2023, 09:20:44 pm
@GetMem
Seems it works.
Title: Re: Controls inside the form disappear in execution.
Post by: jamie on January 30, 2023, 11:28:01 pm
For me it does not matter, it works either way here.
Title: Re: Controls inside the form disappear in execution.
Post by: dsiders on January 31, 2023, 12:17:06 am
@tetrastes
Please try with this:
Code: Pascal  [Select][+][-]
  1.     WM_SETFOCUS:
  2.       begin
  3.         Result := WindowProc(Window, Msg, WParam, LParam);
  4.         Info := GetWin32WindowInfo(Window);
  5.         if Assigned(Info) and Info^.WinControl.IsEnabled then
  6.           InvalidateRect(Info^.WinControl.Handle, nil, True);
  7.         Exit;
  8.       end;
  9.     WM_KILLFOCUS:
  10.       begin
  11.         Result := 0;
  12.         Exit;
  13.       end;              

I tried this variant. It has the same problem with the button and combo-box disappearing. It just happens less frequently.

Tab navigation is alright though.
Title: Re: Controls inside the form disappear in execution.
Post by: jamie on January 31, 2023, 02:38:10 am
Try putting a InvalidateRect(Window, nil, false) within the WM_KILLFOCUS before exit.

 That wil force a refresh of the window.

 I don't see any wrong drawings over here anymore, must be something different between desktops and what you have on it.

 I will say however, I have seen other apps do this from time to time not fully painting their form going out of scope. The GUI in windows places these drawings at a low priority when things get busy.
Title: Re: Controls inside the form disappear in execution.
Post by: dsiders on January 31, 2023, 04:02:29 am
Try putting a InvalidateRect(Window, nil, false) within the WM_KILLFOCUS before exit.

 That wil force a refresh of the window.

 I don't see any wrong drawings over here anymore, must be something different between desktops and what you have on it.

 I will say however, I have seen other apps do this from time to time not fully painting their form going out of scope. The GUI in windows places these drawings at a low priority when things get busy.

I tried this too. Using the code:

Code: Bash  [Select][+][-]
  1. diff --git a/lcl/interfaces/win32/win32wsstdctrls.pp b/lcl/interfaces/win32/win32wsstdctrls.pp
  2. index a1dce61f60..8ba30d1577 100644
  3. --- a/lcl/interfaces/win32/win32wsstdctrls.pp
  4. +++ b/lcl/interfaces/win32/win32wsstdctrls.pp
  5. @@ -583,6 +583,20 @@ begin
  6.            InvalidateRect(Window, nil, True);
  7.          Exit;
  8.        end;
  9. +    WM_SETFOCUS:
  10. +      begin
  11. +        Result := WindowProc(Window, Msg, WParam, LParam);
  12. +        Info := GetWin32WindowInfo(Window);
  13. +        if Assigned(Info) and Info^.WinControl.IsEnabled then
  14. +          InvalidateRect(Info^.WinControl.Handle, nil, True);
  15. +        Exit;
  16. +      end;
  17. +    WM_KILLFOCUS:
  18. +      begin
  19. +        Result := 0;
  20. +        InvalidateRect(Window, nil, False);
  21. +        Exit;
  22. +      end;
  23.      WM_PAINT:
  24.        begin
  25.          Result := WindowProc(Window, Msg, WParam, LParam);
  26.  

It produces exactly the same results as the previous attempt. Controls still disappear but at a reduced frequency. Tab navigation is alright.

Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 31, 2023, 06:43:14 am
@dsiders

Thank you! What are the exact steps to make the controls disappear? I cannot reproduce the issue here, no matter how hard I try. Do you click on the taskbar and back to the application or something else?
Title: Re: Controls inside the form disappear in execution.
Post by: dsiders on January 31, 2023, 07:03:40 am
@dsiders

Thank you! What are the exact steps to make the controls disappear? I cannot reproduce the issue here, no matter how hard I try. Do you click on the taskbar and back to the application or something else?

 I used the process you outlined:

Click on an unused area in the group box about 10 or 12 times.
Click on an unused area in the task bar.
Rinse and repeat until the error happens.

The clicks (on the group box) had to be pretty close together... and it took 8 or 9 cycles to get the error to occur.
Title: Re: Controls inside the form disappear in execution.
Post by: Mr.Madguy on January 31, 2023, 07:11:59 am
For me it's enough to:
1) Create new project
2) Add group box to form
3) Add button to group box
4) Run project
5) Click group box
6) Click task bar
7) Button disappears

Sometimes problem doesn't happen - button just flashes. But in most cases it happens.
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 31, 2023, 07:16:51 am
@dsiders
This is my last attempt:
Code: Pascal  [Select][+][-]
  1.     WM_SETFOCUS, WM_KILLFOCUS:
  2.       begin
  3.         Result := WindowProc(Window, Msg, WParam, LParam);
  4.         Info := GetWin32WindowInfo(Window);
  5.         if Assigned(Info) and Info^.WinControl.IsEnabled then
  6.           InvalidateRect(Info^.WinControl.Handle, nil, True);
  7.         Exit;
  8.       end;

@Mr.Madguy
Did you applied the patch?
Title: Re: Controls inside the form disappear in execution.
Post by: Mr.Madguy on January 31, 2023, 07:33:31 am
Did you applied the patch?
No. Because I think, that something wrong happens here. Other problems should be checked before adding such crutch. First of all, both form and group box have WS_CLIPCHILDREN and WS_CLIPSIBLINGS. And while such problem was understandable back in WinXP era, we have had composite window manager since Vista. Such problems just shouldn't happen in a first place.
Title: Re: Controls inside the form disappear in execution.
Post by: dsiders on January 31, 2023, 07:37:07 am
@dsiders
This is my last attempt:
Code: Pascal  [Select][+][-]
  1.     WM_SETFOCUS, WM_KILLFOCUS:
  2.       begin
  3.         Result := WindowProc(Window, Msg, WParam, LParam);
  4.         Info := GetWin32WindowInfo(Window);
  5.         if Assigned(Info) and Info^.WinControl.IsEnabled then
  6.           InvalidateRect(Info^.WinControl.Handle, nil, True);
  7.         Exit;
  8.       end;

@Mr.Madguy
Did you applied the patch?

I tested with the code:

Code: Bash  [Select][+][-]
  1. diff --git a/lcl/interfaces/win32/win32wsstdctrls.pp b/lcl/interfaces/win32/win32wsstdctrls.pp
  2. index a1dce61f60..4f0df31e84 100644
  3. --- a/lcl/interfaces/win32/win32wsstdctrls.pp
  4. +++ b/lcl/interfaces/win32/win32wsstdctrls.pp
  5. @@ -583,6 +583,14 @@ begin
  6.            InvalidateRect(Window, nil, True);
  7.          Exit;
  8.        end;
  9. +    WM_SETFOCUS, WM_KILLFOCUS:
  10. +      begin
  11. +        Result := WindowProc(Window, Msg, WParam, LParam);
  12. +        Info := GetWin32WindowInfo(Window);
  13. +        if Assigned(Info) and Info^.WinControl.IsEnabled then
  14. +          InvalidateRect(Info^.WinControl.Handle, nil, True);
  15. +        Exit;
  16. +      end;
  17.      WM_PAINT:
  18.        begin
  19.          Result := WindowProc(Window, Msg, WParam, LParam);
  20.  

I've been clicking like a mad man and cannot make this variant reproduce the issue. Tab navigation works as expected. And I see no adverse affects of any kind.

Now, I never saw the issue to begin with when using the application like a normal human being. And this version seems to pass the ADD test.

Time for a cold one.
Title: Re: Controls inside the form disappear in execution.
Post by: balazsszekely on January 31, 2023, 08:11:31 am
@dsiders
Quote
I've been clicking like a mad man and cannot make this variant reproduce the issue. Tab navigation works as expected. And I see no adverse affects of any kind.

Now, I never saw the issue to begin with when using the application like a normal human being. And this version seems to pass the ADD test.

Time for a cold one.
Thanks again. I will wait a few more days just in case.


@Mr.Madguy
Quote
No. Because I think, that something wrong happens here. Other problems should be checked before adding such crutch. First of all, both form and group box have WS_CLIPCHILDREN and WS_CLIPSIBLINGS. And while such problem was understandable back in WinXP era, we have had composite window manager since Vista. Such problems just shouldn't happen in a first place.
Please do check for other problems, maybe you can come up with a better idea.
TinyPortal © 2005-2018