当前位置: 首页 > news >正文

delphi xe10.4 TTASKDIALOG帮助介绍-非官方

Ttaskdialog的官方帮助文件介绍了一些属性,但是找了很久没有看到事件处理函数中具体的参数介绍。实在不知道怎么使用定时关闭功能。

转发一个国外的 非官方的介绍。以做备忘。

https://specials.rejbrand.se/TTaskDialog/

InofficialTTaskDialogDocumentation

Andreas Rejbrand, 2011-02-13

Abstract

See also:Task Dialog Message Box with Fluent Interface

This document is an inofficial documentation for theTTaskDialogclass introduced in Delphi 2009, but, unfortunately, not documented by the Embarcadero team.

As the name of the class suggests, it is a wrapper for the task dialog API introduced in the Microsoft Windows Vista operating system. The lack of documentation caused quite some confusion in the Delphi community. Although any moderately competent software developer can figure out how to use the class by investigating its members and the VCL source code (using the MSDN documentation if necessary), it is convenient to have a reference to consult, so that one doesn't need to rediscover the workings of the class each time it is used.

The aim of this document is to be such a reference.

The Hello World of A Task Dialog

with TTaskDialog.Create(Self) do try Caption := 'My Application'; Title := 'Hello World!'; Text := 'I am a TTaskDialog, that is, a wrapper for the Task Dialog introduced ' + 'in the Microsoft Windows Vista operating system. Am I not adorable?'; CommonButtons := [tcbClose]; Execute; finally Free; end;

Captionis the text shown in the titlebar of the window,Titleis the header, andTextis the body matter of the dialog. Needless to say,Executedisplays the task dialog, and the result is shown below. (We will return to theCommonButtonsproperty in a section or two.)

Being A Well-Behaved Citizen

Of course, the task dialog will crash the program if running under Windows XP, where there is not task dialog API. It will also not work if visual themes are disabled. In any such case, we need to stick to the old-fashionedMessageBox. Hence, in a real application, we would need to do

if (Win32MajorVersion >= 6) and ThemeServices.ThemesEnabled then with TTaskDialog.Create(Self) do try Caption := 'My Application'; Title := 'Hello World!'; Text := 'I am a TTaskDialog, that is, a wrapper for the Task Dialog introduced ' + 'in the Microsoft Windows Vista operating system. Am I not adorable?'; CommonButtons := [tcbClose]; Execute; finally Free; end else MessageBox(Handle, 'I am an ordinary MessageBox conveying the same message in order to support' + 'older versions of the Microsoft Windows operating system (XP and below).', 'My Application', MB_ICONINFORMATION or MB_OK);

In the rest of this article, we will assume that the tax of backwards compatibility is being payed, and instead concentrate on the task dialog alone.

Types of Dialogs. Modal Results

TheCommonButtonsproperty is of typeTTaskDialogCommonButtons, defined as

TTaskDialogCommonButton = (tcbOk, tcbYes, tcbNo, tcbCancel, tcbRetry, tcbClose); TTaskDialogCommonButtons = set of TTaskDialogCommonButton;

This property determines the buttons shown in the dialog (if no buttons are added manually, as we will do later on). If the user clicks any of these buttons, the correspondingTModalResultvalue will be stored in theModalResultproperty as soon asExecutehas returned. TheMainIconproperty determines the icon shown in the dialog, and should -- of course -- reflect the nature of the dialog, as should the set of buttons. Formally an integer,MainIconcan be set to any of the valuestdiNone,tdiWarning,tdiError,tdiInformation, andtdiShield.

with TTaskDialog.Create(Self) do try Caption := 'My Application'; Title := 'The Process'; Text := 'Do you want to continue even though [...]?'; CommonButtons := [tcbYes, tcbNo]; MainIcon := tdiNone; // There is no tdiQuestion if Execute then if ModalResult = mrYes then beep; finally Free; end;

Below are samples of the remaining icon types (shield, warning, and error, respectively):

Finally, you should know that you can use theDefaultButtonproperty to set the default button in the dialog box.

with TTaskDialog.Create(Self) do try Caption := 'My Application'; Title := 'The Process'; Text := 'Do you want to continue even though [...]?'; CommonButtons := [tcbYes, tcbNo]; DefaultButton := tcbNo; MainIcon := tdiNone; if Execute then if ModalResult = mrYes then beep; finally Free; end;

Custom Buttons

You can add custom buttons to a task dialog. In fact, you can set theCommonButtonsproperty to the empty set, and rely entirely on custom buttons (and un unlimited number of such buttons, too). The following real-world example shows such a dialog box:

with TTaskDialog.Create(self) do try Title := 'Confirm Removal'; Caption := 'Rejbrand BookBase'; Text := Format('Are you sure that you want to remove the book file named "%s"?', [FNameOfBook]); CommonButtons := []; with TTaskDialogButtonItem(Buttons.Add) do begin Caption := 'Remove'; ModalResult := mrYes; end; with TTaskDialogButtonItem(Buttons.Add) do begin Caption := 'Keep'; ModalResult := mrNo; end; MainIcon := tdiNone; if Execute then if ModalResult = mrYes then DoDelete; finally Free; end

Command Links

Instead of classical pushbuttons, the task dialog buttons can be command links. This is achieved by setting thetfUseCommandLinksflag (inFlags). Now you can also set theCommandLinkHint(per-button) property:

with TTaskDialog.Create(self) do try Title := 'Confirm Removal'; Caption := 'Rejbrand BookBase'; Text := Format('Are you sure that you want to remove the book file named "%s"?', [FNameOfBook]); CommonButtons := []; with TTaskDialogButtonItem(Buttons.Add) do begin Caption := 'Remove'; CommandLinkHint := 'Remove the book from the catalogue.'; ModalResult := mrYes; end; with TTaskDialogButtonItem(Buttons.Add) do begin Caption := 'Keep'; CommandLinkHint := 'Keep the book in the catalogue.'; ModalResult := mrNo; end; Flags := [tfUseCommandLinks]; MainIcon := tdiNone; if Execute then if ModalResult = mrYes then DoDelete; finally Free; end

ThetfAllowDialogCancellationflag will restore the close system menu item (and titlebar button -- in fact, it will restore the entire system menu).

Don't Throw Technical Details at the End User

You can use the propertiesExpandedTextandExpandedButtonCaptionto add a piece of text (the former) that is only displayed after the user clicks a button (to the left of the text in the latter property) to request it.

with TTaskDialog.Create(self) do try Title := 'Confirm Removal'; Caption := 'Rejbrand BookBase'; Text := Format('Are you sure that you want to remove the book file named "%s"?', [FNameOfBook]); CommonButtons := []; with TTaskDialogButtonItem(Buttons.Add) do begin Caption := 'Remove'; CommandLinkHint := 'Remove the book from the catalogue.'; ModalResult := mrYes; end; with TTaskDialogButtonItem(Buttons.Add) do begin Caption := 'Keep'; CommandLinkHint := 'Keep the book in the catalogue.'; ModalResult := mrNo; end; Flags := [tfUseCommandLinks, tfAllowDialogCancellation]; ExpandButtonCaption := 'Technical information'; ExpandedText := 'If you remove the book item from the catalogue, the corresponding *.book file will be removed from the file system.'; MainIcon := tdiNone; if Execute then if ModalResult = mrYes then DoDelete; finally Free; end

The image below shows the dialog after the user has clicked the button to reveal the additional details.

If you add thetfExpandFooterAreaflag, the additional text will instead be shown in the footer:

In any case, you can let the dialog open with the details already expanded by adding thetfExpandedByDefaultflag.

Custom Icons

You can use any custom icon in a task dialog, by using thetfUseHiconMainflag and specifying theTIconto use in theCustomMainIconproperty.

with TTaskDialog.Create(self) do try Caption := 'About Rejbrand BookBase'; Title := 'Rejbrand BookBase'; CommonButtons := [tcbClose]; Text := 'File Version: ' + GetFileVer(Application.ExeName) + #13#10#13#10'Copyright © 2011 Andreas Rejbrand'#13#10#13#10'http://english.rejbrand.se'; Flags := [tfUseHiconMain, tfAllowDialogCancellation]; CustomMainIcon := Application.Icon; Execute; finally Free; end

Hyperlinks

You can even use HTML-like hyperlinks in the dialog (inText,Footer, andExpandedText), if you only add thetfEnableHyperlinksflag:

with TTaskDialog.Create(self) do try Caption := 'About Rejbrand BookBase'; Title := 'Rejbrand BookBase'; CommonButtons := [tcbClose]; Text := 'File Version: ' + GetFileVer(Application.ExeName) + #13#10#13#10'Copyright © 2011 Andreas Rejbrand'#13#10#13#10'<a href="http://english.rejbrand.se">http://english.rejbrand.se</a>'; Flags := [tfUseHiconMain, tfAllowDialogCancellation, tfEnableHyperlinks]; CustomMainIcon := Application.Icon; Execute; finally Free; end

Notice, however, that nothing happens when you click the link. The action of the link must be implemented manually, which -- of course -- is a good thing. To do this, respond to theOnHyperlinkClickedevent, which is aTNotifyEvent. The URL of the link (thehrefof theaelement, that is) is stored in theURLpublic property of theTTaskDialog:

procedure TForm1.TaskDialogHyperLinkClicked(Sender: TObject); begin if Sender is TTaskDialog then with Sender as TTaskDialog do ShellExecute(0, 'open', PChar(URL), nil, nil, SW_SHOWNORMAL); end; procedure TForm1.FormCreate(Sender: TObject); begin with TTaskDialog.Create(self) do try Caption := 'About Rejbrand BookBase'; Title := 'Rejbrand BookBase'; CommonButtons := [tcbClose]; Text := 'File Version: ' + GetFileVer(Application.ExeName) + #13#10#13#10'Copyright © 2011 Andreas Rejbrand'#13#10#13#10'<a href="http://english.rejbrand.se">http://english.rejbrand.se</a>'; Flags := [tfUseHiconMain, tfAllowDialogCancellation, tfEnableHyperlinks]; OnHyperlinkClicked := TaskDialogHyperlinkClicked; CustomMainIcon := Application.Icon; Execute; finally Free; end end;

The Footer

You can use theFooterandFooterIconproperties to create a footer. The icon property accepts the same values as theMainIconproperty.

with TTaskDialog.Create(self) do try Caption := 'My Application'; Title := 'A Question'; Text := 'This is a really tough one...'; CommonButtons := [tcbYes, tcbNo]; MainIcon := tdiNone; FooterText := 'If you do this, then ...'; FooterIcon := tdiWarning; Execute; finally Free; end

Using thetfUseHiconFooterflag and theCustomFooterIconproperty, you can use any custom icon in the footer, in the same way as you can choose your own main icon.

A Checkbox

Using theVerificationTextstring property, you can add a checkbox to the footer of the task dialog. The caption of the checkbox is the property.

with TTaskDialog.Create(self) do try Caption := 'My Application'; Title := 'A Question'; Text := 'This is a really tough one...'; CommonButtons := [tcbYes, tcbNo]; MainIcon := tdiNone; VerificationText := 'Remember my choice'; Execute; finally Free; end

You can make the checkbox initially checked by specifying thetfVerificationFlagCheckedflag. Unfortunately, due to a bug (?) in the VCL implementation of theTTaskDialog, the inclusion of this flag whenExecutehas returned doesn't reflect the final state of the checkbox. To keep track of the checkbox, the application thus needs to remember the initial state and toggle an internal flag as a response to eachOnVerificationClickedevent, which is triggered every time the state of the checkbox is changed during the modality of the dialog.

Radio Buttons

Radio buttons can be implemented in a way resembling how you add custom push buttons (or command link buttons):

with TTaskDialog.Create(self) do try Caption := 'My Application'; Title := 'A Question'; Text := 'This is a really tough one...'; CommonButtons := [tcbOk, tcbCancel]; MainIcon := tdiNone; with RadioButtons.Add do Caption := 'This is one option'; with RadioButtons.Add do Caption := 'This is another option'; with RadioButtons.Add do Caption := 'This is a third option'; if Execute then if ModalResult = mrOk then ShowMessage(Format('You chose %d.', [RadioButton.Index])); finally Free; end

http://www.gsyq.cn/news/1437733.html

相关文章:

  • 应用通过cmd启动失败时报错,如何取消开机启动
  • Cadence AMS数模混合仿真保姆级教程:从Virtuoso Testbench到多线程加速全流程
  • 别再死记公式了!用Python手撸一个LDA分类器,从鸢尾花数据集开始
  • Argo浮标数据怎么用?手把手教你用Python替代Matlab计算海洋热容与盐容贡献
  • 昆山名酒回收电话评测:上海附近上门回收名酒/昆山五粮液回收/昆山八大回收/从核心维度选靠谱服务商 - 优质品牌商家
  • 保姆级教程:在Ubuntu 22.04上,用RTX 40系显卡从零搞定DeepStream 6.4(含CUDA 12.2和TensorRT 8.6.1.6)
  • SEED数据集实战:用Python+MNE批量读取脑电数据,附完整代码与通道映射表
  • AI副业月入6000?我扒了数据,真相扎心了
  • 2026年重庆闲置名表名包回收可靠机构排行盘点 - 优质品牌商家
  • Xshell 7免费版连接VMware Linux保姆级教程:从密钥对登录到文件传输全搞定
  • 告别iSaver!用Wallpaper Engine免费搞定Win10动态锁屏(附保姆级设置流程)
  • Codex 子代理:串行 vs 并行,快多少
  • 2026年白色硅灰厂家选型技术推荐:纳米级微硅粉/超细微硅粉/四川微硅粉厂家/四川硅灰/核心指标解析 - 优质品牌商家
  • AI写论文的宝藏工具!4款AI论文写作助手,让你的写作过程更顺畅
  • 如何用VinXiangQi打造你的智能象棋AI助手:从零开始到专业级分析
  • 深入xv6内核:为每个进程创建独立内核页表到底解决了什么问题?
  • 保姆级教程:在Linux上从零配置TongLINKQ 8.1.15.2客户端,实现与服务端通信
  • Beyond Compare 5逆向工程:RSA非对称加密授权机制深度解析与密钥生成器实战
  • 2026年台州税务代理公司选对=合规高效 企赢税务智能财税推荐(含联系方式) - 本地品牌推荐
  • 2026年Trae与Claude Code优缺点对比:深度横评解析
  • Cora和Citeseer数据集上可直接运行的GCN链路预测代码包(含预处理、训练与评估)
  • 2026 年郑州化妆品柜展柜厂家技术与服务分析报告
  • STM32F103扫地机器人实战工程:FreeRTOS多任务调度+IAP远程升级+电池与传感器全链路管理
  • 告别系统升级焦虑:Ubuntu 22.04 LTS 到 24.04 LTS 保姆级升级指南(含 do-release-upgrade 详解)
  • 告别Ubuntu 22.04默认Dock:这几个gsettings命令和Gnome扩展让你效率翻倍
  • 十年 PM 走心总结:职场管理者的底层逻辑
  • C++如何与C语言混合编程_在C++项目中调用C库函数的extern “C“方法
  • MATLAB版LMS自适应滤波实操包:带运行录像、可调参数源码与收敛效果可视化
  • 从零开始搭建知识问答系统
  • 【Redis】 五大基础数据类型 底层原理深度解析