制表符不能在Delphi XE2消息对话框中使用-替代方法? [英] Tab characters no longer work in Delphi XE2 message dialogs - alternatives?

查看:121
本文介绍了制表符不能在Delphi XE2消息对话框中使用-替代方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Win 7 64位上使用Delphi XE2创建32位应用程序...

Using Delphi XE2 on Win 7 64 bit creating a 32 bit app...

在Delphi 6中,我们使用消息中的制表符来创建漂亮的外观,多行双列对话框。

In Delphi 6 we used the tab character within a message to create a nice looking, multi-line double-column dialog.

str := 'Left item:' + #9#9 + 'Right Item' + #13#10 +
       'Next left item: + #9 + 'Next Right Item' + ...

if MessageDlg(str, mtConfirmation,[mbYes,mbNo],0) = mrYES then...

这会为用户创建一个排列良好的数据列表无需提出自定义表格即可看到此特定问题。右列对齐良好,可以轻松清晰地查看数据。

This creates a nicely lined up list of data for the user to see without the need for a custom form just to ask this particular question. The right column is nicely aligned and makes it easy to see the data clearly.

在Delphi XE2中,嵌入字符串中的制表符(#9)被完全忽略,因此根本没有空格。使用#32确实会创建一个空格,但不能像制表符(#9)那样很好地对齐。我是否遇到了一些Unicode问题?

In Delphi XE2 the tab characters (#9) embedded within the string are completely ignored and there is no white space at all. Using #32 does create a space but does not nicely line up like the tab character (#9). Am I running into some Unicode issue?

除了使用自定义表单之外,还有其他建议可以恢复这种格式吗?

Any suggestions out there to get this formatting back other than using a custom form?

干杯!

编辑:

当然,在我发布问题后,我想出了一个

Of course, after I post a question I figure out a couple different workarounds.

首先,使用Application.MessageBox()确实可以保持制表符的间距。

First, using Application.MessageBox() does maintain the tab character spacing.

其次奇怪的是,下面的代码可以正常工作并使用制表符保持空白。

Secondly and oddly, this code below works and maintains the proper white space with the tab characters.

procedure TForm1.Button1Click(Sender: TObject);
var AMsgDialog : TForm;
var str : string;
begin
  str := 'Left item:' + #9#9 + 'Right Item' + #13#10 +
         'Next left item:' + #9#9 + 'Next Right Item';
  AMsgDialog := CreateMessageDialog(str, mtConfirmation,[mbYes,mbNo],0);
  try
    if AMsgDialog.ShowModal = mrYES then begin
      //do something
    end;
  finally
    AMsgDialog.Release;
  end;
end;

不确定为什么以这种方式创建消息对话框时会保留制表符间距,而以前的方式则不会

Not sure why creating a message dialog this way would maintain the tab character spacing when the old way would not.

我知道当我调用MessageDlg()时会遇到相同的CreateMessageDialog函数,因此在除去制表符之间必须有一些区别。我无法跟踪代码来找出剥离制表符的原因。

I know the same CreateMessageDialog function is hit when I call MessageDlg() so there must be something in between stripping out the tab characters. I was not able to trace into the code to find out what was stripping the tab characters.

希望这可以帮助其他人。

Hopefully this helps someone else out.

推荐答案

取决于某些内部检查,例如Windows版本(大于或等于vista), UseLatestCommonDialogs 变量,并且当前的视觉样式是否为原生Windows主题。 MessageDlg 使用TTaskMessageDialog(<一个href = http://docwiki.embarcadero.com/Libraries/en/Vcl.Dialogs.TCustomTaskDialog> TCustomTaskDialog )类,该类在内部调用 TaskDialogIndirect WinApi函数,此函数由Windows本身,据我所知,没有办法以特殊方式识别 Tab 字符。

Depending of some internals checks like the Windows version (greater or equal than vista), the value of the UseLatestCommonDialogsvariable and if the current visual Style is the native windows theme. The MessageDlg uses the TTaskMessageDialog(TCustomTaskDialog) class which internally call the TaskDialogIndirect WinApi function, This function is handled by Windows itself and as far i know there is not option to recognize the Tab chars in a special way.

否则,如果满足上述条件之一与 MessageDlg 不匹配使用 CreateMessageDialog 函数创建对话框。此方法使用VCL和WinApi调用来绘制对话框本身,使用带有 DT_EXPANDTABS 标志的 DrawText 函数,可扩展制表符。

Otherwise when one of the above conditions doesn't match the MessageDlg uses the CreateMessageDialog function to create a dialog. This method draw the dialog itself using the VCL and WinApi calls, the text of the body is drawn using the DrawText function with the DT_EXPANDTABS flag included which Expands tab characters.

所以 MessageDlg 函数在内部使用 CreateMessageDialog 时识别 Tab 字符(您可以强制执行此行为将UseLatestCommonDialogs的值设置为false)。

So the only way which the MessageDlg function recognizes the Tab chars is when uses the CreateMessageDialog internally (you can force this behavior setting the value of UseLatestCommonDialogs to false).

这篇关于制表符不能在Delphi XE2消息对话框中使用-替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆