gpt4 book ai didi

delphi - 带有自定义按钮标题的通用对话框

转载 作者:行者123 更新时间:2023-12-03 14:55:44 26 4
gpt4 key购买 nike

我知道这个问题以前就已经出现过(例如 Best way to show customized message dialogs ),但我仍然找不到我想要的东西。

我是这样开始的:

class function TAttracsForm.MessageDlg(const aMsg: string; aDlgType: TMsgDlgType; Buttons: TMsgDlgButtons; aCaptions: array of String; aDefault: TMsgDlgBtn): TModalResult;
var
vDlg: TForm;
i: Integer;
begin
if aButtons.Count = aCaptions.Count then
begin
vDlg := CreateMessageDialog(aMsg, aDlgType, Buttons);
try
for i := 0 aCaptions.Count - 1 do
TButton(vDlg.FindComponent(Buttons[i].Caption)).Caption := aCaptions[i];

vDlg.Position := poDefaultPosOnly;
Result := vDlg.ShowModal;
finally
vDlg.Free;
end;
end;
end;

调用看起来像:

if (MessageDlg('Really quit application ?', mtWarning, 
[mbNo, mbCancel, mbYes], {'No save', 'Cancel', 'Save'}) = mrYes) then

但是上面的代码当然不能编译。我不知道如何在循环中获取一组中的一项以及如何在开始时获取它的总数。

最佳答案

您可以使用此代码:

function MyMessageDlg(CONST Msg: string; DlgTypt: TmsgDlgType; button: TMsgDlgButtons;
Caption: ARRAY OF string; dlgcaption: string): Integer;
var
aMsgdlg: TForm;
i: Integer;
Dlgbutton: Tbutton;
Captionindex: Integer;
begin
aMsgdlg := createMessageDialog(Msg, DlgTypt, button);
aMsgdlg.Caption := dlgcaption;
aMsgdlg.BiDiMode := bdRightToLeft;
Captionindex := 0;
for i := 0 to aMsgdlg.componentcount - 1 Do
begin
if (aMsgdlg.components[i] is Tbutton) then
Begin
Dlgbutton := Tbutton(aMsgdlg.components[i]);
if Captionindex <= High(Caption) then
Dlgbutton.Caption := Caption[Captionindex];
inc(Captionindex);
end;
end;
Result := aMsgdlg.Showmodal;
end;

例如:

MyMessageDlg('Hello World!', mtInformation, [mbYes, mbNo],
['Yessss','Noooo'], 'New MessageDlg Box'):

关于delphi - 带有自定义按钮标题的通用对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5417843/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com