打开 NSOpenPanel 的 ShowModal 表单在 Delphi Firemonkey OSX 中被强制关闭
ShowModal form that opens NSOpenPanel is force closed in Delphi Firemonkey OSX
我正在使用代码@http://jed-software.com/blog/?p=538在OSX上打开一个对话框来选择文件夹
我正在使用 Form2.ShowModal
创建一个表单,在这个表单上我通过一个按钮调用上面的 SelectDirectory
函数。使用 ShowModal
创建的表单会在 NSOpenPanel
也关闭后立即关闭...表单 OnClose
事件不会触发,ModalResult
Form2.ShowModal
调用是 mrNone (0)
,所以我一直无法找到阻止这种不需要的行为的方法。 LOpenDir.runModal;
结果以某种方式迫使我的 Form2
也关闭
任何帮助都会很棒,谢谢。
您需要在平台服务中设置 FRestartModal
标志。
LDlgResult := LOpenDir.runModal;
RestartModal;
不幸的是,这有点令人讨厌,因为该标志隐藏在单元实现部分的 TPlatformCocoa class 中。我不喜欢使用 RTTI 进行黑客攻击,但不幸的是我还没有找到更好的方法。所以给你:
procedure RestartModal;
//Hack: Set the FRestartModal flag in TPlatformCocoa
var
Context: TRttiContext;
RttiType: TRttiType;
Field: TRttiField;
FModalStack: TStack<TObject>;
FPlatformService: TObject;
begin
FPlatformService := TObject(TPlatformServices.Current.GetPlatformService(IFMXWindowService)); // trick for getting the MacOS Platformservice
RttiType := Context.GetType(FPlatformService.ClassType);
Field := RttiType.GetField('FModalStack'); // get private field using RTTI
Assert(Field <> nil);
FModalStack := PPointer(Field.GetValue(FPlatformService).GetReferenceToRawData)^;
if (FModalStack <> nil) and (FModalStack.Count > 0) then
begin
Field := RttiType.GetField('FRestartModal');
Field.SetValue(FPlatformService, True);
end;
end;
我正在使用代码@http://jed-software.com/blog/?p=538在OSX上打开一个对话框来选择文件夹
我正在使用 Form2.ShowModal
创建一个表单,在这个表单上我通过一个按钮调用上面的 SelectDirectory
函数。使用 ShowModal
创建的表单会在 NSOpenPanel
也关闭后立即关闭...表单 OnClose
事件不会触发,ModalResult
Form2.ShowModal
调用是 mrNone (0)
,所以我一直无法找到阻止这种不需要的行为的方法。 LOpenDir.runModal;
结果以某种方式迫使我的 Form2
也关闭
任何帮助都会很棒,谢谢。
您需要在平台服务中设置 FRestartModal
标志。
LDlgResult := LOpenDir.runModal;
RestartModal;
不幸的是,这有点令人讨厌,因为该标志隐藏在单元实现部分的 TPlatformCocoa class 中。我不喜欢使用 RTTI 进行黑客攻击,但不幸的是我还没有找到更好的方法。所以给你:
procedure RestartModal;
//Hack: Set the FRestartModal flag in TPlatformCocoa
var
Context: TRttiContext;
RttiType: TRttiType;
Field: TRttiField;
FModalStack: TStack<TObject>;
FPlatformService: TObject;
begin
FPlatformService := TObject(TPlatformServices.Current.GetPlatformService(IFMXWindowService)); // trick for getting the MacOS Platformservice
RttiType := Context.GetType(FPlatformService.ClassType);
Field := RttiType.GetField('FModalStack'); // get private field using RTTI
Assert(Field <> nil);
FModalStack := PPointer(Field.GetValue(FPlatformService).GetReferenceToRawData)^;
if (FModalStack <> nil) and (FModalStack.Count > 0) then
begin
Field := RttiType.GetField('FRestartModal');
Field.SetValue(FPlatformService, True);
end;
end;