Using Delphi XE2 on Win 7 64 bit creating a 32 bit app…
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.
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?
Cheers!
EDIT:
Of course, after I post a question I figure out a couple different workarounds.
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.
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.
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. TheMessageDlguses the TTaskMessageDialog(TCustomTaskDialog) class which internally call theTaskDialogIndirectWinApi 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.Otherwise when one of the above conditions doesn’t match the
MessageDlguses theCreateMessageDialogfunction to create a dialog. This method draw the dialog itself using the VCL and WinApi calls, the text of the body is drawn using theDrawTextfunction with theDT_EXPANDTABSflag included which Expands tab characters.So the only way which the
MessageDlgfunction recognizes the Tab chars is when uses theCreateMessageDialoginternally (you can force this behavior setting the value of UseLatestCommonDialogs to false).