Hum, this is embarrassing. I cannot reproduce the bug in a new project.
However: If I comment the check for fsFormStyle like so:
WM_MENUSELECT:
begin
TargetObject := GetMenuItemObject((HIWORD(Integer(WParam)) and MF_POPUP) <> 0);
// Check if the menu was the maximized icon menu for an MDI child window and ignore it in that case
if (LoWord(Integer(WParam))=0) and (lWinControl=Application.MainForm) {and (Application.MainForm.FormStyle=fsMDIForm)} then
begin
MaximizedActiveChild := False;
if SendMessage(Win32WidgetSet.MDIClientHandle, WM_MDIGETACTIVE, 0, Windows.WPARAM(@MaximizedActiveChild)) <> 0 then
begin
if MaximizedActiveChild then
TargetObject := nil;
end;
end;
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.
WM_MENUSELECT:
begin
TargetObject := GetMenuItemObject((HIWORD(Integer(WParam)) and MF_POPUP) <> 0);
// Check if the menu was the maximized icon menu for an MDI child window and ignore it in that case
if (LoWord(Integer(WParam))=0) then showmessage('LoWord = 0');
if (lWinControl=Application.MainForm) then showmessage('Form is MainForm') else showMessage('Not main form');
//error is generated here
if (Application.MainForm.FormStyle=fsnormal) then showMessage('Style is normal') ;
//error is generated here
if (LoWord(Integer(WParam))=0) and (lWinControl=Application.MainForm) {and (Application.MainForm.FormStyle=fsMDIForm)} then
begin
MaximizedActiveChild := False;
if SendMessage(Win32WidgetSet.MDIClientHandle, WM_MDIGETACTIVE, 0, Windows.WPARAM(@MaximizedActiveChild)) <> 0 then
begin
if MaximizedActiveChild then
TargetObject := nil;
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!