0

I am trying to display a string with tabulator characters inside of a MessageDlg. The tabs inside the string are not recognized and displayed properly. I'm pretty certain it has to do with the MessageDlg and not the string itself as it displays properly inside of a TRichEdit component.

I've not yet tried to replicate the result in other versions of Delphi and this is the only relevant article I've found so far: https://forums.embarcadero.com/message.jspa?messageID=710405

sInfo := #13 +  'Name:' + #9 + sName + #13 +
                 'Surname:' + #9 + sSurname + #13 +
                 'Address:' + #9 + sAddress + #13 +
                 'E-mail:' + #9 + sEmail + #13 +
                 'Phone:' + #9 + sCell;

iConfirm := MessageDlg('Add the following member info: ' + sInfo,
     mtConfirmation, mbYesNo, 0);

I expect the string to be displayed in 2 columns inside the MessageDlg but it is displayed as follows: 'Name:Janrich'

2 Answers2

1

You can make it work when setting UseLatestCommonDialogs := False; - well, at least partly. It looks like you don't have control over the tab size, which makes the outcome a bit unreliable.

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
0

Possible duplicate of Tab characters no longer work in Delphi XE2 message dialogs - alternatives?

I personally would create a form for this purpose, containing a readonly Memo control. The form would be shown using ShowModal. This has the advantage that the user can copy-paste the text. Using buttons that have the ModalResult property, you can also get the Yes/No result back.

sInfo := #13 +  'Name:' + #9 + sName + #13 +
                 'Surname:' + #9 + sSurname + #13 +
                 'Address:' + #9 + sAddress + #13 +
                 'E-mail:' + #9 + sEmail + #13 +
                 'Phone:' + #9 + sCell;

memoMessageBox := TMemoMessageBoxForm.Create;
try
  memoMessageBox.Memo1.Text := sInfo;
  dlgRes := memoMessageBox.ShowModal; // ModalResult
finally
  FreeAndNil(memoMessageBox);
end;

if dlgRes = mrYes then ...
Daniel Marschall
  • 3,739
  • 2
  • 28
  • 67
  • Well, I'm not aware of any other purpose of `TAB` characters in a multi line text than to align text. A fixed number of spaces can never replace a `TAB` character. – Tom Brunberg Jul 08 '19 at 14:20
  • This can't be any good, no way this text is aligned. Dispiriting to see the up vote! – David Heffernan Jul 08 '19 at 15:51
  • My post contained more than just the string replacement. First, I also found out the duplicate thread (which you have used to flag the thread). Then, I provided TWO ideas. One IF the OP don't want alignment (then space replacement) and one idea if the OP wants alignment, then I would make a Form with a Memo component. So I do not understand the downvotes. I wanted to give at least a few ideas instead of just saying "it is not possible with WinAPI" – Daniel Marschall Jul 09 '19 at 07:43
  • If it's duplicate you should not answer. You should vote to close. And when you do answer, it is expected that you address the specific question asked. By all means add additional ideas, but the baseline is to answer the question. The is no doubt that alignment is the intent. It is literally stated in the question. *I expect the string to be displayed in 2 columns*. Also, standard dialog boxes do support copying to the clipboard. Try it. – David Heffernan Jul 10 '19 at 05:52