diff --git a/docs/xml/lcl/dialogs.xml b/docs/xml/lcl/dialogs.xml index 4a22dcb8ed..5a8100edf6 100644 --- a/docs/xml/lcl/dialogs.xml +++ b/docs/xml/lcl/dialogs.xml @@ -2774,29 +2774,14 @@ or you can make your own set. Show a question to the user and get a response - QuestionDlg has the same functionality as MessageDlg
- -except for the parameter Buttons which is of a different type.
- -You can define your own captions and return values of this function.
-
- - -Buttons is a list of TModalResult (defined as constants [mrNone..MrYesToAll] in - -) and strings.
- -For each TModalResult a button is - created.
- -To set a custom caption, add a string after a button.
-
- - - -The default TModalResults defined in controls.pp (mrNone..mrLast)
- -doesn't need a caption. The default captions will be used.
+

QuestionDlg has the same functionality as MessageDlg except for the parameter Buttons which is of a different type.
+You can define your own captions and return values of this function. +

Buttons is a list of TModalResult (defined as constants [mrNone..MrYesToAll] in ) and strings.
+For each TModalResult a button is created.
+To set a custom caption, add a string after a button. You can use the special string parameters 'isdefault' and 'iscancel' to setup the default and cancel buttons. +

The default TModalResults defined in controls.pp (mrNone..mrLast) don't need a caption. The default captions will be used. +

+
diff --git a/lcl/include/promptdialog.inc b/lcl/include/promptdialog.inc index 754b4c1752..dab977f055 100644 --- a/lcl/include/promptdialog.inc +++ b/lcl/include/promptdialog.inc @@ -924,42 +924,53 @@ begin end; // get options - CurOptions := ''; - IsDefault := False; - IsCancel := False; - if (i <= High(Buttons)) then + if (SysUtils.CompareText(CurBtnCaption,'isdefault')=0) + or (SysUtils.CompareText(CurBtnCaption,'iscancel')=0) then begin HasOptions := True; - case Buttons[i].VType of - vtString: CurOptions := Buttons[i].VString^; - vtAnsiString: CurOptions := AnsiString(Buttons[i].VAnsiString); - vtChar: CurOptions := Buttons[i].VChar; - vtPChar: CurOptions := Buttons[i].VPChar; - vtPWideChar: CurOptions := Buttons[i].VPWideChar; - vtWideChar: CurOptions := AnsiString(Buttons[i].VWideChar); - vtWidestring: CurOptions := AnsiString(WideString(Buttons[i].VWideString)); - else - HasOptions := False; - end; - if HasOptions then + CurOptions := CurBtnCaption; + CurBtnCaption := ''; + end else + begin + CurOptions := ''; + HasOptions := False; + if (i <= High(Buttons)) then begin - if SysUtils.CompareText(CurOptions,'isdefault')=0 then - begin - if DialogButtons.DefaultButton <> nil then - raise Exception.Create('TQuestionDlg.CreateQuestionDlg only one button can be default'); - IsDefault := True; - end else - if SysUtils.CompareText(CurOptions,'iscancel')=0 then - begin - if DialogButtons.CancelButton <> nil then - raise Exception.Create('TQuestionDlg.CreateQuestionDlg only one button can be cancel'); - IsCancel := True; - end else - raise Exception.Create('TQuestionDlg.CreateQuestionDlg option expected at ' - +IntToStr(i)+' but "'+CurOptions+'" found.'); + HasOptions := True; + case Buttons[i].VType of + vtString: CurOptions := Buttons[i].VString^; + vtAnsiString: CurOptions := AnsiString(Buttons[i].VAnsiString); + vtChar: CurOptions := Buttons[i].VChar; + vtPChar: CurOptions := Buttons[i].VPChar; + vtPWideChar: CurOptions := Buttons[i].VPWideChar; + vtWideChar: CurOptions := AnsiString(Buttons[i].VWideChar); + vtWidestring: CurOptions := AnsiString(WideString(Buttons[i].VWideString)); + else + HasOptions := False; + dec(i); // prevent the following inc(i) + end; inc(i); end; end; + IsDefault := False; + IsCancel := False; + if HasOptions then + begin + if SysUtils.CompareText(CurOptions,'isdefault')=0 then + begin + if DialogButtons.DefaultButton <> nil then + raise Exception.Create('TQuestionDlg.CreateQuestionDlg only one button can be default'); + IsDefault := True; + end else + if SysUtils.CompareText(CurOptions,'iscancel')=0 then + begin + if DialogButtons.CancelButton <> nil then + raise Exception.Create('TQuestionDlg.CreateQuestionDlg only one button can be cancel'); + IsCancel := True; + end else + raise Exception.Create('TQuestionDlg.CreateQuestionDlg option expected at ' + +IntToStr(i)+' but "'+CurOptions+'" found.'); + end; if CurBtnCaption = '' then begin