Einzelnen Beitrag anzeigen

Rollo62

Registriert seit: 15. Mär 2007
4.096 Beiträge
 
Delphi 12 Athens
 
#4

AW: Delphi Rio MessageDialogSync

  Alt 13. Jan 2021, 15:50
Das einmal in eine Klasse/Funktion zuverpacken würde reichen,
so machen es die _Sync Methoden auch.

Mal so hingekritzelt als Funktion ...
So müsste das eigentlich funktionieren (Tippfehler ausgenommen).
Delphi-Quellcode:

procedure MyDlg_Message(const AMessage: string;
                        const ADialogType: TMsgDlgType;
                        const AButtons: TMsgDlgButtons;
// const AHelpContext: LongInt;
                        const ACloseDialogProc: TInputCloseDialogProc = nil );



procedure MyDlg_Message(const AMessage: string;
                        const ADialogType: TMsgDlgType;
                        const AButtons: TMsgDlgButtons;
// const AHelpContext: LongInt;
                        const ACloseDialogProc: TInputCloseDialogProc );
var
    LProcDlg : TInputCloseDialogProc;
    LCloseDialogProc : TInputCloseDialogProc;
    LEvent : TEvent;
    LRes : TWaitResult;
begin
    LCloseDialogProc := ACloseDialogProc;

    if not Assigned( LClodeDialogProc ) then
        LEvent := TEvent.Create(nil, True, False, 'MyEventName')
    else
        LEvent := nil;

    try
        LProcDlg := procedure( const AResult: TModalResult)
                    begin
                        if Assigned( LCloseDialogProc ) then
                        begin
                            LCloseDialogProc( AResult );
                        end
                        else
                        begin // Want a blocking Message
                            if Assigned( LEvent ) then
                            begin
                                LEvent.SetEvent;
                            end;
                        end;
                    end;

        FMX.DialogService.TDialogService
        {} .MessageDialog( AMessage,
                           ADialogType,
                           AButtons,
                           TMsgDlgBtn.mbCancel,
                           0,
                           LProcDlg ); // ACloseDialogProc);
  
    finally
        if Assigned( LEvent ) then
        begin
            LRes := LEvent.WaitFor( INFINITE ); //<== or better Timeout here
            case LRes of
               wrSignaled : { => Done    };
               wrTimeout : { => Timeout };
               wrAbandoned : {Terminate};
               wrError : { Logging };
            end;

            LEvent.Free;
        end;
    end;

end;

Geändert von Rollo62 (13. Jan 2021 um 16:13 Uhr)
  Mit Zitat antworten Zitat