我正在使用德尔福 10.4。这是一个 Windows VCL 应用程序。
我想在我的程序中将我所有的 ShowMessage、MessageDlg 和 MessageBox 调用转换为 TaskDialogs。当我尝试这样做时,我无法让 TaskDialog 显示任何内容。
所以我所做的是创建一个新的最小 VCL 应用程序,只需添加一个按钮和一个 TaskDialog 到它:
这是我的代码:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
TaskDialog1: TTaskDialog;
procedure MyMessageBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
procedure TForm1.MyMessageBox;
begin
Form1.TaskDialog1.Caption := 'My Application';
Form1.TaskDialog1.Title := 'Hello World!';
Form1.TaskDialog1.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?';
Form1.TaskDialog1.CommonButtons := [tcbClose];
Form1.TaskDialog1.Execute;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MyMessageBox;
end;
{$R *.dfm}
begin
Application.Run;
end.
那工作得很好。运行它并按下 Button1 时,我得到:
所以现在我去我的应用程序。我在主窗体中添加了一个按钮,并将 MyMessageBox 过程设置为:
procedure TLogoAppForm.MyMessageBox;
begin
ShowMessage('ShowMessage ......................................');
Application.MessageBox('Application.MessageBox ...........................', 'Error', 0);
MessageDlg('MessageDlg ................................', mtWarning, [mbOk], 0);
LogoAppForm.TaskDialog1.Caption := 'My Application';
LogoAppForm.TaskDialog1.Title := 'Hello World!';
LogoAppForm.TaskDialog1.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?';
LogoAppForm.TaskDialog1.CommonButtons := [tcbClose];
LogoAppForm.TaskDialog1.Execute;
end;
在我的应用程序中正确按下按钮会依次打开每个 ShowMessage、MessageBox 和 MessageDlg 窗口,但在关闭 MessageDlg 窗口后,TaskDialog 什么也没有出现。
有谁知道是什么可能导致 TaskDialog 在我的应用程序中无法工作以及如何解决这个问题?