mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 17:59:16 +02:00
lcl: questiondlg: fixed button with both IsDefault and IsCancel
git-svn-id: branches/fixes_1_6@50938 -
This commit is contained in:
parent
505523a4b0
commit
2fb7b843ab
@ -2781,7 +2781,19 @@ For each TModalResult a button is created. <br/>
|
|||||||
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.
|
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.
|
||||||
</p><p>The default TModalResults defined in controls.pp (mrNone..mrLast) don't need a caption. The default captions will be used.
|
</p><p>The default TModalResults defined in controls.pp (mrNone..mrLast) don't need a caption. The default captions will be used.
|
||||||
</p>
|
</p>
|
||||||
</descr>
|
case QuestionDlg('COPYING',
|
||||||
|
'Abort?',
|
||||||
|
mtConfirmation,
|
||||||
|
[mrNo, '&No','IsDefault',
|
||||||
|
mrYes,'&Yes'],0)
|
||||||
|
of
|
||||||
|
mrYes : ShowMessage('You clicked Yes');
|
||||||
|
mrNo : ShowMessage('You clicked No');
|
||||||
|
else
|
||||||
|
// mrCancel
|
||||||
|
ShowMessage('You cancelled the dialog.');
|
||||||
|
end;
|
||||||
|
</descr>
|
||||||
<errors/>
|
<errors/>
|
||||||
<seealso>
|
<seealso>
|
||||||
<link id="MessageDlg"/>
|
<link id="MessageDlg"/>
|
||||||
|
@ -911,11 +911,32 @@ end;
|
|||||||
|
|
||||||
function QuestionDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;
|
function QuestionDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;
|
||||||
Buttons: array of const; HelpCtx: Longint): TModalResult;
|
Buttons: array of const; HelpCtx: Longint): TModalResult;
|
||||||
|
|
||||||
|
function GetNextCaption(var i: integer; out aCaption: string): boolean;
|
||||||
|
begin
|
||||||
|
aCaption:='';
|
||||||
|
if (i > High(Buttons)) then exit(false);
|
||||||
|
Result:=true;
|
||||||
|
case Buttons[i].VType of
|
||||||
|
vtString: aCaption := Buttons[i].VString^;
|
||||||
|
vtAnsiString: aCaption := AnsiString(Buttons[i].VAnsiString);
|
||||||
|
vtChar: aCaption := Buttons[i].VChar;
|
||||||
|
vtPChar: aCaption := Buttons[i].VPChar;
|
||||||
|
vtPWideChar: aCaption := Buttons[i].VPWideChar;
|
||||||
|
vtWideChar: aCaption := AnsiString(Buttons[i].VWideChar);
|
||||||
|
vtWidestring: aCaption := AnsiString(WideString(Buttons[i].VWideString));
|
||||||
|
else
|
||||||
|
Result:=false;
|
||||||
|
end;
|
||||||
|
if Result then
|
||||||
|
inc(i);
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
DialogButtons: TDialogButtons;
|
DialogButtons: TDialogButtons;
|
||||||
i: integer;
|
i: integer;
|
||||||
CurBtnValue: TModalResult;
|
CurBtnValue: TModalResult;
|
||||||
CurBtnCaption, CurOptions: String;
|
CurBtnCaption, CurOptions, CurCaption: String;
|
||||||
HasOptions: Boolean;
|
HasOptions: Boolean;
|
||||||
IsDefault, IsCancel: Boolean;
|
IsDefault, IsCancel: Boolean;
|
||||||
NewButton: TDialogButton;
|
NewButton: TDialogButton;
|
||||||
@ -934,71 +955,26 @@ begin
|
|||||||
CurBtnValue := Buttons[i].VInteger;
|
CurBtnValue := Buttons[i].VInteger;
|
||||||
inc(i);
|
inc(i);
|
||||||
|
|
||||||
// get button caption
|
// get button caption and flags
|
||||||
CurBtnCaption := '';
|
CurBtnCaption := '';
|
||||||
if (i <= High(Buttons)) then
|
|
||||||
begin
|
|
||||||
case Buttons[i].VType of
|
|
||||||
vtString: CurBtnCaption := Buttons[i].VString^;
|
|
||||||
vtAnsiString: CurBtnCaption := AnsiString(Buttons[i].VAnsiString);
|
|
||||||
vtChar: CurBtnCaption := Buttons[i].VChar;
|
|
||||||
vtPChar: CurBtnCaption := Buttons[i].VPChar;
|
|
||||||
vtPWideChar: CurBtnCaption := Buttons[i].VPWideChar;
|
|
||||||
vtWideChar: CurBtnCaption := AnsiString(Buttons[i].VWideChar);
|
|
||||||
vtWidestring: CurBtnCaption := AnsiString(WideString(Buttons[i].VWideString));
|
|
||||||
else
|
|
||||||
dec(i); // prevent the following inc(i)
|
|
||||||
end;
|
|
||||||
inc(i);
|
|
||||||
end;
|
|
||||||
|
|
||||||
// get options
|
|
||||||
if (SysUtils.CompareText(CurBtnCaption,'isdefault')=0)
|
|
||||||
or (SysUtils.CompareText(CurBtnCaption,'iscancel')=0) then
|
|
||||||
begin
|
|
||||||
HasOptions := True;
|
|
||||||
CurOptions := CurBtnCaption;
|
|
||||||
CurBtnCaption := '';
|
|
||||||
end else
|
|
||||||
begin
|
|
||||||
CurOptions := '';
|
|
||||||
HasOptions := False;
|
|
||||||
if (i <= High(Buttons)) 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;
|
|
||||||
dec(i); // prevent the following inc(i)
|
|
||||||
end;
|
|
||||||
inc(i);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
IsDefault := False;
|
IsDefault := False;
|
||||||
IsCancel := False;
|
IsCancel := False;
|
||||||
if HasOptions then
|
while GetNextCaption(i,CurCaption) do
|
||||||
begin
|
begin
|
||||||
if SysUtils.CompareText(CurOptions,'isdefault')=0 then
|
if (SysUtils.CompareText(CurCaption,'isdefault')=0) then begin
|
||||||
begin
|
|
||||||
if DialogButtons.DefaultButton <> nil then
|
if DialogButtons.DefaultButton <> nil then
|
||||||
raise Exception.Create('TQuestionDlg.CreateQuestionDlg only one button can be default');
|
raise Exception.Create('TQuestionDlg.CreateQuestionDlg only one button can be default');
|
||||||
IsDefault := True;
|
IsDefault:=true;
|
||||||
end else
|
end
|
||||||
if SysUtils.CompareText(CurOptions,'iscancel')=0 then
|
else if (SysUtils.CompareText(CurCaption,'iscancel')=0) then begin
|
||||||
begin
|
|
||||||
if DialogButtons.CancelButton <> nil then
|
if DialogButtons.CancelButton <> nil then
|
||||||
raise Exception.Create('TQuestionDlg.CreateQuestionDlg only one button can be cancel');
|
raise Exception.Create('TQuestionDlg.CreateQuestionDlg only one button can be cancel');
|
||||||
IsCancel := True;
|
IsCancel:=true
|
||||||
end else
|
end
|
||||||
raise Exception.Create('TQuestionDlg.CreateQuestionDlg option expected at '
|
else if CurBtnCaption='' then
|
||||||
+IntToStr(i)+' but "'+CurOptions+'" found.');
|
CurBtnCaption:=CurCaption
|
||||||
|
else
|
||||||
|
raise Exception.Create('TQuestionDlg.CreateQuestionDlg option expected at '+IntToStr(i)+', but found "'+CurCaption+'"');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if CurBtnCaption = '' then
|
if CurBtnCaption = '' then
|
||||||
|
Loading…
Reference in New Issue
Block a user