假模态对话使用显示? [英] Fake modal dialog using Show?

查看:111
本文介绍了假模态对话使用显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有几个模块,分别位于主窗体的一个选项卡中。
当使用对话框时,调用ShowModal是方便的,因为你知道对话框何时完成。但是对于用户而言,它是不好的,因为锁定整个程序,直到对话框关闭。



我想要一个本地模态的对话框。所以一个模块可以打开一个对话框,它只锁定当前模块。用户仍然可以切换到另一个模块并继续工作。如果用户返回到第一个模块,则对话框在那里等待关闭,然后用户可以继续在该模块中工作。



我必须为这样应用程序中的所有对话框都可以使用。
我有一个baseclass的所有对话框TAttracsForm,我认为这里是添加我的Show()方法的地方。



这应该锁定访问所有的wincontrols只在当前模块中。
它应该模拟对ShowModal()的调用。我如何才能实现这一点?



感谢

解决方案

现在几乎实施了本地模态对话框。
当TForms Enabled属性设置为False时,整个窗体被从输入锁定。我的模块只是TForm的后代。



我的ViewManager类决定了什么模块是当前的添加/关闭模块等有两种新方法。 LockCurrentView和UnLOckCurrentView。

  function TViewManager.LockCurrentView:TChildTemplate; 
begin
结果:= CurrentView;
Result.Enabled:= False;
Result.VMDeactivate; // DeActivate该模块的菜单和工具栏
end;

程序TViewManager.UnLockCurrentView(aCallerForm:TChildTemplate);
begin
aCallerForm.VMActivate; //激活此模块的菜单和工具栏
aCallerForm.Enabled:= True;
结束

TAttracsForm是所有对话框的基础类。我覆盖FormClose并添加一个新的方法ShowLocalModal来调用而不是ShowModal。我还必须添加一个TNotifyEvent OnAfterDestruction,当对话框关闭时调用。

  procedure TAttracsForm.FormClose(Sender:TObject; var Action:TCloseAction); 
begin
如果分配(fCallerForm)然后
begin
ClientMainForm.ViewManager.UnLockCurrentView(fCallerForm as TChildTemplate);

如果分配(OnAfterDestruction)然后
OnAfterDestruction(Self);

动作:= caFree;
结束
结束

{每个模块调用一个对话框模态。
限制是模块的创建者必须是TChildtemplate。
几个模态对话框不能用这个方法堆叠。}
程序TAttracsForm.ShowLocalModal(aNotifyAfterClose:TNotifyEvent);
begin
fCallerForm:= ClientMainForm.ViewManager.LockCurrentView; //锁定当前模块并返回它
PopupParent:= fCallerForm;
OnAfterDestruction:= aNotifyAfterClose;
显示;
结束

使用简单对话框进行的一些测试看起来很有前途。所以该模块只需要调用具有TNotifyEvent作为参数的ShowLocalModal(myMethod)。当对话框关闭时调用此方法。


My application have several modules, each in one tab on the mainform. When using a dialog it is convenient to call ShowModal because you know when the dialog is finished. But for the user it is not good as it lock the whole program until the dialog closes.

I want to have a locally modal dialog. So one module can open a dialog and it locks current module only. The user can still switch to another module and continue to work. If the user return to the first module the dialog is there waiting for close before the user can continue to work in that module.

I have to make some kind of framework for this that all dialogs in the application can use. I have a baseclass for all dialogs TAttracsForm and I think here is the place to add my Show() method.

This should lock access to all wincontrols only in the current module. It should simulate a call to ShowModal(). How can I achieve this ?

Regards

解决方案

I have actually almost implemented local modal dialogs now. It is built around that when a TForms Enabled property is set To False the whole Form is locked from input. And my modules is just a descendant from TForm.

My ViewManager class that decide what modules is current add/close modules etc got 2 new methods. LockCurrentView and UnLOckCurrentView.

function TViewManager.LockCurrentView: TChildTemplate;
begin
  Result := CurrentView;
  Result.Enabled := False;
  Result.VMDeactivate;         // DeActivate menus and toolbas for this module
end;

procedure TViewManager.UnLockCurrentView(aCallerForm: TChildTemplate);
begin
  aCallerForm.VMActivate;           // Activate menus and toolbas for this module
  aCallerForm.Enabled := True;
end;

TAttracsForm is the baseclass of all dialogs. I Override FormClose and add a new method ShowLocalModal to call instead of ShowModal. I also have to add a TNotifyEvent OnAfterDestruction to be called when the dialog is closed.

procedure TAttracsForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Assigned(fCallerForm) then      
  begin
    ClientMainForm.ViewManager.UnLockCurrentView(fCallerForm as TChildTemplate);

    if Assigned(OnAfterDestruction) then
      OnAfterDestruction(Self);

    Action := caFree;
  end;
end;

{ Call to make a dialog modal per module.
  Limitation is that the creator of the module must be a TChildtemplate.
  Several modal dialogs cannot be stacked with this method.}
procedure TAttracsForm.ShowLocalModal(aNotifyAfterClose: TNotifyEvent);
begin
  fCallerForm := ClientMainForm.ViewManager.LockCurrentView;    // Lock current module and return it
  PopupParent := fCallerForm;
  OnAfterDestruction := aNotifyAfterClose;
  Show;
end;

Some test with simple dialogs looks promising. So the module just have to call ShowLocalModal(myMethod) which have a TNotifyEvent as parameter. This method is called when the dialog is closed.

这篇关于假模态对话使用显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆