私はまだローカルモーダルダイアログ(LMD)で作業しています。詳細については、this questionを参照してください。単純なケースではうまく動作しますが、ダイアログに結果が表示され、発信者に通知したい場合があります。コールはShow()と非同期であるため、コール後に結果を得ることはできません。イベントメソッドに1つまたは複数の値を返すにはどうすればよいですか?
私の質問は、メソッドTModule.myEventにTLMD_Dialog.btnOkClickメソッドから1つまたはいくつかの値を返す方法です。
私はこれに関与し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
私はいくつかの語彙を発明していますが、私にとってモーダルダイアログは、ShowModalを呼び出すことによって基礎となるGUIをロックします。私たちの考えは、アプリケーションのローカル部分、この場合はモジュールだけをロックすることです。次に、ローカルモーダルの式。 –