【发布时间】: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