Refactoring TTaskDialog:

- TWSTaskDialog.Execute: return integer (modal result of the dialog) instead of boolean
- Idem for related functions and methods
This commit is contained in:
Bart 2023-07-20 10:55:48 +02:00
parent e1dd886c07
commit c3c73c48fc
4 changed files with 21 additions and 14 deletions

View File

@ -233,8 +233,12 @@ begin
//temporary show new, then old dialog, both in emulated mode (regardless of Flags)
LCLTaskDialog.TaskDialogIndirect := nil;
Result := TWSTaskDialogClass(WidgetSetClass).Execute(Self);
debugln(['TWSTaskDialogClass(WidgetSetClass).Execute(Self)=',Result]);
ButtonID := TWSTaskDialogClass(WidgetSetClass).Execute(Self);
FModalResult := ButtonIDToModalResult(ButtonID);
Result := (ButtonID >= 0);
debugln(['TWSTaskDialogClass(WidgetSetClass).Execute(Self)=',ButtonID,', Result=',Result]);
debugln(['New: ButtonID=',ButtonID]);
debugln(['New: FModalResult=',FModalResult]);
FillChar(TaskDlg, SizeOf(LCLTaskDialog.TTaskDialog), 0);
@ -263,9 +267,12 @@ begin
ButtonID := TaskDlg.Execute(TD_COMMONBUTTONS(CommonButtons), DefBtn, TD_FLAGS(Flags), TF_DIALOGICON(MainIcon), TF_FOOTERICON(FooterIcon),
DefRB, FWidth, ParentWnd, tfForceNonNative in Flags, tfEmulateClassicStyle in Flags, @DoOnButtonClickedHandler);
debugln(['TaskDlg.Execute()=',ButtonID,', Result=',Result]);
debugln(['Old: ButtonID=',ButtonID]);
Result := ButtonID>=0;
FModalResult := ButtonIDToModalResult(ButtonID);
debugln(['Old: FModalResult=',FModalResult]);
//ToDo move FirstButtonIndex and FirstRadioButtonIndex to interface section Dialogs unit.

View File

@ -161,7 +161,7 @@ type
TWin32WSTaskDialog = class(TWSTaskDialog)
public
class function Execute(const ADlg: TCustomTaskDialog): Boolean; override;
class function Execute(const ADlg: TCustomTaskDialog): Integer; override;
end;
function OpenFileDialogCallBack(Wnd: HWND; uMsg: UINT; {%H-}wParam: WPARAM;
@ -1578,7 +1578,7 @@ var
TaskDialogIndirect: function(AConfig: pointer; Res: PInteger;
ResRadio: PInteger; VerifyFlag: PBOOL): HRESULT; stdcall;
class function TWin32WSTaskDialog.Execute(const ADlg: TCustomTaskDialog): Boolean;
class function TWin32WSTaskDialog.Execute(const ADlg: TCustomTaskDialog): Integer;
begin
//writeln('TWin32WSTaskDialog.Execute');
Result := inherited Execute(ADlg);

View File

@ -37,7 +37,7 @@ type
constructor CreateNew(AOwner: TComponent; Num: Integer = 0); override;
function Execute: Boolean;
function Execute: Integer;
public
/// the labels corresponding to the Task Dialog main elements
Element: array[tdeContent..tdeMainInstruction] of TLabel;
@ -59,7 +59,7 @@ var
TaskDialog_Translate: TTaskDialogTranslate;
function ExecuteLCLTaskDialog(const ADlg: TTaskDialog): Boolean;
function ExecuteLCLTaskDialog(const ADlg: TTaskDialog): Integer;
implementation
@ -143,12 +143,12 @@ end;
{ -------------- }
function ExecuteLCLTaskDialog(const ADlg: TTaskDialog): Boolean;
function ExecuteLCLTaskDialog(const ADlg: TTaskDialog): Integer;
var
DlgForm: TLCLTaskDialog;
begin
debugln('ExecuteLCLTaskDialog');
Result := False;
Result := -1;
DlgForm := TLCLTaskDialog.CreateNew(ADlg);
try
Result := DlgForm.Execute;
@ -167,14 +167,14 @@ begin
KeyPreview := True;
end;
function TLCLTaskDialog.Execute: Boolean;
function TLCLTaskDialog.Execute: Integer;
var
mRes, I: Integer;
aParent: HWND;
begin
debugln(['TLCLTaskDialog.Execute: Assigned(FDlg)=',Assigned(FDlg)]);
if not Assigned(FDlg) then
Exit(False);
Exit(-1);
SetupControls;
aParent := FDlg.ParentWindow;
@ -193,8 +193,8 @@ begin
mRes := ShowModal;
Result := (mRes > 0);
Result := ShowModal;
//Result := (mRes > 0);
//ToDo implement this
(*

View File

@ -106,7 +106,7 @@ type
TWSTaskDialogClass = class of TWSTaskDialog;
TWSTaskDialog = class(TWSLCLComponent)
published
class function Execute(const ADlg: TCustomTaskDialog): Boolean; virtual;
class function Execute(const ADlg: TCustomTaskDialog): Integer; virtual;
end;
{ WidgetSetRegistration }
@ -198,7 +198,7 @@ end;
{ TWSTaskDialog }
class function TWSTaskDialog.Execute(const ADlg: TCustomTaskDialog): Boolean;
class function TWSTaskDialog.Execute(const ADlg: TCustomTaskDialog): Integer;
begin
//writeln('TWSTaskDialog.Execute: Assigned(ADlg)=',Assigned(ADlg));
Result := ExecuteLCLTaskDialog(TTaskDialog(ADlg));