【问题标题】:Form losses modal attribute after changing app style更改应用样式后表单丢失模态属性
【发布时间】:2015-05-19 14:46:01
【问题描述】:

我创建了一个模态表单,用户可以在其中设置 (vcf) 样式。

我使用这个代码:

procedure TfrmMain.btnChangeSkinClick(Sender: TObject);
begin
  frmSkins:= TfrmSkins.Create(NIL);
  frmSkins.ShowModal;
end;

procedure TfrmSkins.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 Action:= caFree;
end;

然后在 frmSkins 中,我在一个列表框中列出所有可用的 vcf 文件。当用户单击样式时,我会像这样加载该样式:

procedure TfrmSkins.lBoxClick(Sender: TObject);
VAR  StyleInfo : TStyleInfo;
begin
    ...
    sSkinFile:= lBox.Items[lBox.ItemIndex];
    if TStyleManager.IsValidStyle(sSkinFile, StyleInfo) then
      begin
       TStyleManager.LoadFromFile(sSkinFile);
       TStyleManager.SetStyle(StyleInfo.Name);
      end;

    // this will 'fix' half of the problem, bringing the form up. But it won't make the form modal again.
    Application.ProcessMessages;
    BringToFront;
end;

调用 SetStyle 后,frmSkins 被退回(在主窗体下)并永久失去 modal 属性!

我做错了什么?

【问题讨论】:

  • 第二个代码块在什么时候被调用?你为什么打电话给Application.CreateForm?仅将其称为主要形式。你为什么不使用try/finally
  • 我猜是VCL中的窗口重新创建代码未能正确设置所有者窗口。在 VCL 术语中称为弹出父级。 VCL 样式存在缺陷也就不足为奇了。

标签: delphi delphi-xe7


【解决方案1】:

这个问题在 Delphi Rio.3 中仍然存在。只有一个真正的解决方案。不要使用模态表单,而是创建一个不会失去焦点的迷你应用程序,允许用户单击控件,并使用一个保存按钮来更新主应用程序的注册表。然后在主应用程序中使用一些方案来恢复执行,读取注册表,并在需要时使用 TrySetStyle。

【讨论】:

  • 这不是有点极端吗?
【解决方案2】:

如果您的主表单显示模态表单,您可以使用此解决方法:

type
  TChildForm = class(TForm)
    procedure FormDestroy(Sender: TObject);
  protected
    procedure WndProc(var Msg: TMessage); override;
  end;

implementation

procedure TChildForm.FormDestroy(Sender: TObject);
begin
    Application.MainForm.Enabled := true;
end;

procedure TChildForm.WndProc(var Msg: TMessage);
begin
    case Msg.Msg of
    CM_CUSTOMSTYLECHANGED:
    begin
        Application.MainForm.Enabled := false;
    end;
    end;
    inherited WndProc(Msg);
end;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-25
    • 2016-12-06
    • 1970-01-01
    • 2018-04-04
    相关资源
    最近更新 更多