我找到了解决方法。
当您创建具有所有者的表单时,FireMonkey 应该将所有者传递给 Windows CreateWindowEx 函数,但它不会。
在单元FMX.Platform.Win中,在CreateWindow()函数中,改变这个:
Wnd := CreateWindowEx(ExStyle, WindowClass.lpszClassName, PChar(AForm.Caption), Style,
Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),
GetDesktopWindow, 0, hInstance, nil);
到这里:
// If there's an owner, and it's a form, then create the window as a child
if (AForm <> nil) and (AForm.Owner <> nil) and (AForm.Owner is TForm) then
begin
// Child window
Wnd := CreateWindowEx(ExStyle, WindowClass.lpszClassName, PChar(AForm.Caption), Style,
Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),
HandleToHWND(TForm(AForm.Owner).Handle), 0, hInstance, nil);
end
else
begin
// Desktop window
Wnd := CreateWindowEx(ExStyle, WindowClass.lpszClassName, PChar(AForm.Caption), Style,
Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),
GetDesktopWindow, 0, hInstance, nil);
end;
因此,如果您要创建子表单,尤其是模态表单,请确保在创建父表单时将其指定为所有者:
MyModalForm := TMyModalForm.Create(MyParentForm);
MyModalForm.ShowModal;
然后,修复后一切都会按预期工作。
不要忘记从项目设置中的自动创建表单列表中删除子表单。