MessageDlg does not recognize 'tab'-characters(#9) in Delphi 10.3

1.4k Views Asked by At

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

There are 2 best solutions below

4
Daniel Marschall On

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 ...
0
Uwe Raabe On

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.