저는 여전히 로컬 모달 대화 상자 (LMD)로 작업하고 있습니다. 자세한 내용은 this question을 참조하십시오. 이제는 간단한 경우에 잘 작동하지만 때로는 호출자에게 알리고 싶은 대화 상자의 결과가 있습니다. 호출이 Show()와 비동기 적이기 때문에 호출 후에 결과를 얻을 수는 없습니다.이벤트 메서드에 하나 이상의 값을 반환하려면 어떻게해야합니까?
그럼 내 질문은 방법 TModule.myEvent 메서드 TLMD_Dialog.btnOkClick 메서드에서 하나 또는 여러 값을 반환 할 수 있습니다?
나는이에 관여하는 3 개 개의 유닛을 가지고 : 당신이 TNotifyEvent
사용하지 않는, 이
// 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를 잠급니다. 우리의 아이디어는 응용 프로그램의 로컬 부분 (이 경우에는 모듈)을 잠그는 것입니다. 다음 표현식은 지역 모달입니다. –