我仍在使用我的本地模式对话框(LMD)。有关更多信息,请参阅this question。对于简单的情况,它现在可以正常工作,但是有时在我想要通知调用者的对话框中有结果。由于调用与Show()是异步的,我不能简单地在调用后获得结果。如何将一个或多个值返回给我的事件方法?
所以我的问题是如何返回一个或多个值从方法TLMD_Dialog.btnOkClick方法TModule.myEvent?
我参与这个3个单元: (请注意,TLMD_Dialog从TAttracsForm继承)
// Module.pas
procedure myEvent(Sender: TObject);
procedure TModule.btnCallDlg(Sender: TObject);
begin
if Supports(lhaHandle.CurrentBoldObject, IObject, vMyObject) then
TModalDialog.Execute(param1, param2, myEvent);
end;
procedure TModule.myEvent(Sender: TObject);
begin
// Some code that react on result of the LMD dialog
end;
// AttracsForm.pas
type
TAttracsForm = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
fCallerForm: TForm; // May be replaced by check PopupParent but a separate variable may be safer
fOnAfterDestruction: TNotifyEvent;
published
procedure ShowLocalModal(aNotifyAfterClose: TNotifyEvent=nil);
end;
procedure TAttracsForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Assigned(fCallerForm) then // fCallerForm not assinged means that ShowLocalModal is not called. The old way to show dialog is used
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;
// LMD_Dialog.pas (inherit from TAttracsForm)
class procedure Execute(aParam: IBoldObject; aNotifyEvent: TNotifyEvent);
class procedure TLMD_Dialog.Execute(aParam: IBoldObject; aNotifyEvent: TNotifyEvent);
begin
with Self.Create(nil) do
begin
// Do preparation
ShowLocalModal(aNotifyEvent);
end;
end;
procedure TLMD_Dialog.btnOkClick(Sender: TObject);
begin
// Do something before close down
// Set Result of the dialog
Close;
end;
您不应该将其称为本地模式对话框,而是窗口模式或表单模式对话框(与系统模式或任务模式对话框)。 – mghie 2009-08-26 06:45:53
嗯,也许我发明了一些自己的词汇,但对我来说,模式对话框通过调用ShowModal来锁定底层GUI。我们的想法是只锁定应用程序的本地部分,在这种情况下是模块。然后表达本地模态。 – 2009-08-26 10:22:49