Как насчет этого:
type
TButtonInfo = record
MsgDlgBtn: TMsgDlgBtn;
Caption: string;
end;
function ButtonInfo(MsgDlgBtn: TMsgDlgBtn; const Caption: string): TButtonInfo;
begin
Result.MsgDlgBtn := MsgDlgBtn;
Result.Caption := Caption;
end;
const
ModalResults: array[TMsgDlgBtn] of Integer = (
mrYes, mrNo, mrOk, mrCancel, mrAbort, mrRetry, mrIgnore, mrAll, mrNoToAll,
mrYesToAll, 0, mrClose);
function FindDialogButton(Form: TForm; MsgDlgBtn: TMsgDlgBtn): TButton;
var
i: Integer;
Component: TComponent;
begin
for i := 0 to Form.ComponentCount-1 do begin
Component := Form.Components[i];
if Component is TButton then begin
if TButton(Component).ModalResult=ModalResults[MsgDlgBtn] then begin
Result := TButton(Component);
exit;
end;
end;
end;
Result := nil;
end;
function MessageDlg(
const aMsg: string;
aDlgType: TMsgDlgType;
const Buttons: array of TButtonInfo;
aDefault: TMsgDlgBtn
): TModalResult;
var
i: Integer;
MsgDlgButtons: TMsgDlgButtons;
vDlg: TForm;
begin
MsgDlgButtons := [];
for i := low(Buttons) to high(Buttons) do begin
Assert(not (Buttons[i].MsgDlgBtn in MsgDlgButtons));//assert uniqueness
Include(MsgDlgButtons, Buttons[i].MsgDlgBtn);
end;
vDlg := CreateMessageDialog(aMsg, aDlgType, MsgDlgButtons, aDefault);
try
for i := low(Buttons) to high(Buttons) do begin
FindDialogButton(vDlg, Buttons[i].MsgDlgBtn).Caption := Buttons[i].Caption;
end;
vDlg.Position := poDefaultPosOnly;
Result := vDlg.ShowModal;
finally
vDlg.Free;
end;
end;
procedure Test;
begin
MessageDlg(
'Really quit application ?',
mtWarning,
[ButtonInfo(mbNo, 'Do&n''t save'), ButtonInfo(mbCancel, '&Cancel'), ButtonInfo(mbYes,'&Save')],
mbYes
);
end;