Recent

Author Topic: [Solved] PopUp menu no longer working  (Read 1747 times)

AL

  • Full Member
  • ***
  • Posts: 181
[Solved] PopUp menu no longer working
« on: August 14, 2020, 10:12:01 pm »
I had a PopUpMenu working until I updated Lazarus.
Previous version was 62510 actual 63734 ( also tried 63727)
When I access the PopUp I get a sigsev error.
The Linux version is working with the same revision (63734)

Can you provide any help?

Thank you
« Last Edit: August 16, 2020, 08:24:30 pm by AL »
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

wp

  • Hero Member
  • *****
  • Posts: 7521
Re: PopUp menu no longer working
« Reply #1 on: August 14, 2020, 10:15:33 pm »
Please write a small demo which shows the error and post a bug report with it. If I remember correctly there were changes related to MDI some months ago.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

AL

  • Full Member
  • ***
  • Posts: 181
Re: PopUp menu no longer working
« Reply #2 on: August 15, 2020, 04:01:51 am »
Hum, this is embarrassing. I cannot reproduce the bug in a new project.
However:  If I comment the check for fsFormStyle like so:
Code: Pascal  [Select][+][-]
  1.    
  2.     WM_MENUSELECT:
  3.     begin
  4.       TargetObject := GetMenuItemObject((HIWORD(Integer(WParam)) and MF_POPUP) <> 0);
  5.       // Check if the menu was the maximized icon menu for an MDI child window and ignore it in that case
  6.       if (LoWord(Integer(WParam))=0) and (lWinControl=Application.MainForm) {and (Application.MainForm.FormStyle=fsMDIForm)} then
  7.       begin
  8.         MaximizedActiveChild := False;
  9.         if SendMessage(Win32WidgetSet.MDIClientHandle, WM_MDIGETACTIVE, 0, Windows.WPARAM(@MaximizedActiveChild)) <> 0 then
  10.         begin
  11.           if MaximizedActiveChild then
  12.             TargetObject := nil;
  13.         end;
  14.       end;
  15.  
then everything is working fine.
So this is really during the check for fsFormStyle that the error arise.
Not sure why.
My form is fsNormal.   Changing for fsMDIForm also generate the sigsev.

I made a few check by placing ShowMesages in the code
 (LoWord(Integer(WParam)) is 0
the form is the Mainform.
Reading the formstyle generate an error.
Code: Pascal  [Select][+][-]
  1.   WM_MENUSELECT:
  2.     begin
  3.       TargetObject := GetMenuItemObject((HIWORD(Integer(WParam)) and MF_POPUP) <> 0);
  4.       // Check if the menu was the maximized icon menu for an MDI child window and ignore it in that case
  5.       if (LoWord(Integer(WParam))=0) then showmessage('LoWord = 0');
  6.       if (lWinControl=Application.MainForm) then showmessage('Form is MainForm') else showMessage('Not main form');
  7.  
  8.       //error is generated here
  9.       if (Application.MainForm.FormStyle=fsnormal) then showMessage('Style is normal') ;
  10.       //error is generated here
  11.  
  12.       if (LoWord(Integer(WParam))=0) and (lWinControl=Application.MainForm) {and (Application.MainForm.FormStyle=fsMDIForm)} then
  13.       begin
  14.         MaximizedActiveChild := False;
  15.         if SendMessage(Win32WidgetSet.MDIClientHandle, WM_MDIGETACTIVE, 0, Windows.WPARAM(@MaximizedActiveChild)) <> 0 then
  16.         begin
  17.           if MaximizedActiveChild then
  18.             TargetObject := nil;
  19.         end;                              

I am clueless as to why a new form does not generate an error and an old form does when reading the formstyle property!
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

AL

  • Full Member
  • ***
  • Posts: 181
Re: PopUp menu no longer working
« Reply #3 on: August 15, 2020, 03:55:47 pm »
I made some more testing today.
So this is not really a PopUpmenu problem. But rather the address of application.mainform.formstyle in win32int.pp
FormStyle inquiry (if mainform.formstyle = fsNormal ...) if called from a program unit does not generate an error.
Only if called from within win32int unit then it will generate an error (sigsev).
So this is possibly a pointer thing, or compiler directive beyond my expertise.
Since my form is not a MDI, I have commented the culprit section in win32callback.inc for now.

The unit where my from is created  is compiled with {$mode objfpc}{$H+}   if that may make a difference.
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

AL

  • Full Member
  • ***
  • Posts: 181
Re: PopUp menu no longer working
« Reply #4 on: August 16, 2020, 08:13:19 pm »
OK , this was bothering me, so I made more tests.
My mainform ( the form where most things happen) is called MainForm!
BUT..., it is not the first created!
By definition Application.mainform is the first created.
So I moved my MainForm to the top of the list so it is the first created
Now no more errors.
It is probably a bad idea to call a form Mainform as it seems mainform is a property of Tapplication.
 
Thank you.
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

wp

  • Hero Member
  • *****
  • Posts: 7521
Re: [Solved] PopUp menu no longer working
« Reply #5 on: August 16, 2020, 11:10:29 pm »
Having understood the conditions for the crash, could you now try again to create a simple demo project? Because I think this is a bug, and you should submit a bug report with this demo project. I cannot believe that the behavior of a form should depend on its name being MainForm although it is not the MainForm of the Application (except for the confusion, of course).
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

AL

  • Full Member
  • ***
  • Posts: 181
Re: [Solved] PopUp menu no longer working
« Reply #6 on: August 17, 2020, 01:15:47 am »
I will try to do it in the next days
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

 

TinyPortal © 2005-2018