Search code examples
delphimessagebox

Change Caption of MessageBox with some variable inside message in Delphi


How to change the title of message dialog box with some variable inside message. I've tried

Application.MessageBox('x * y = ' + result, 'this is title', MBICONINFORMATION); 

but it shows an error said Incompatible types: 'String' and 'PAnsiChar', I know this is because the 'result' variable is not allow. Any solve? Thanks before


Solution

  • I reccomend you to use Format function as follows:

    Application.MessageBox(PChar(Format('x * y = %s', [result])), 'this is title', MB_ICONINFORMATION);