Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to display final result / messages

Status
Not open for further replies.

LEICJDN1

Technical User
Nov 27, 2002
201
GB
Hi,

Need to display final output on screen or certain messages during program operation. Currently write onto form1.canvas (the only form) but would rather a new box appeared with the message, and need 'OK' or 'Cancel' boxes to report back the decision and continue appropriately.

Should I do this by creating a new form for each event or is there a better way?

Thanks again.
 
Why can't you use the standard message box:

function MessageBox(const Text, Caption: PChar; Flags: Longint): Integer;

Value Numeric value Meaning

IDOK 1 The user chose the OK button.
IDCANCEL 2 The user chose the Cancel button.


 
showmessage for OK like this:
Showmessage('This is a message.');

for other button options you can use MessageDlg like this:

if MessageDlg(LSTR_Message, mtWarning, [mbYes, mbNo],0) = mrYes then

and use any of these buttons (like [mbYes, mbNo] above):
mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore,
mbAll, mbNoToAll, mbYesToAll, mbHelp

I think you need to include Dialogs in your uses clause (I usually do this in the interface section, but you can probably do it in implementation if you want) in order to use showmessage and MessageDlg.
Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
Thanks,

ShowMessage will do the job nicely!

Thanks.
 
Actually either work well. Another query I can't find the answer to in the help file is how to carriage return in a string.

In other words i want my message to read:

Analysis complete
Result 1 = 10
Result 2 = 10

Mean result = 10

These results have been logged in the following file:
filename


Do I need multiple strings? Or can I specify the format of the string internally?

Thanks!
 
Try...

s := 'Analysis complete' + chr(10)
+ 'Result 1 = 10' + chr(10)
+ 'Result 2 = 10' + chr(10)
+ chr(10)
+ 'Mean result = 10';

showmessage(s);
If it's stupid but it works, it isn't stupid
 
Add either #13 or Chr(13) like this

showmessage('Result 1 = ' + inttoStr(i) + #13 +
'Result 2 = ' + inttoStr(j) + chr(13) +
'Mean Result = ' + FloatToStr(Mean([i,j])));

The use of Mean() requires the Math unit. Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
Slightly simpler is to use
Code:
#10
in place of
Code:
chr(10)
as in:
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage( 'Analysis complete' + #10
             + 'Result 1 = 10' + #10
             + 'Result 2 = 10' + #10
             + #10
             + 'Mean result = 10');
end;
By simpler, I mean fewer keystrokes. The results are equivalent.
 
What is the difference between #10 Linefeed and #13 CarriageReturn? Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
For use with ShowMessage, there is no practical difference. When cobbling together lines of text is is customary to use both as a 2-character sequence:
Code:
const
  CRLF = #13 + #10;

procedure TfrmMain.Button2Click(Sender: TObject);
begin
  ShowMessage( 'Analysis complete' + CRLF
             + 'Result 1 = 10' + CRLF
             + 'Result 2 = 10' + CRLF + CRLF
             + 'Mean result = 10');
end;
Some text processing programs choke if you don't have both CR and LF to signal the end of a line. As always, it depends on how the data are going to be used.

 
Thanks.
Spent ages combing the help file for thart one! Trouble is, unless you know the topic area name it is very difficult to find things easily!

However, this forum saved the day again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top