带有自定义按钮标题的通用对话框
我知道这个问题从以前就已经出现了(例如显示自定义消息对话框的最佳方式),但我仍然找不到我想要的。
我是这样开始的:
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
但是上面的代码当然不能编译。我不知道如何在循环中获取一组中的一项以及如何在开始时获取它的总数。
I know this issue have been up since before (ex. Best way to show customized message dialogs), but I still don't find what I want.
I started like this:
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;
And the call would look like:
if (MessageDlg('Really quit application ?', mtWarning,
[mbNo, mbCancel, mbYes], {'No save', 'Cancel', 'Save'}) = mrYes) then
But the above code of course don't compile. I don't know how to get one item of an set in the loop and how to get the total count of it in the beginning.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用此代码:
例如:
you can use this code:
For example:
像这样的东西怎么样:
How about something like this:
我写了这段代码:(我来自克罗地亚,所以文本是克罗地亚语)
使用示例:
I write this code: (I am from Croatia, so the texts are in Croatian)
Example of use :
为了跟进我在因尝试将一组按钮与字符串数组匹配而导致的关键错误的已接受答案中的评论,这里是完整的工作版本(因为我的评论几乎没有关于如何实现的线索)。
我将变量重命名为更明显,重新排序参数以匹配典型的对话框调用并且更符合逻辑。
用法: -
MyMessageDlg('Confirm', 'Yes, No or Maybe?', mtConfirmation, ['Yes','No','Maybe']);
其中返回值为
0
表示是
,1
表示否
&2
代表也许
。干杯:)
To follow up my comment in the Accepted Answer of the critical bug due to attempting to match buttons in a set to an array of strings, here is the complete working version (as my comment had few clues on how to implement).
I renamed variables to be more obvious, reordered the parameters to match the typical dialog call and to be more logical.
Usage: -
MyMessageDlg('Confirm', 'Yes, No or Maybe?', mtConfirmation, ['Yes','No','Maybe']);
Where the return value will be
0
forYes
,1
forNo
&2
forMaybe
.Cheers :)