Which Pascal are you using?
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
OK, FP is very compatible with Delphi.
Add the Dialogs unit to your uses clause. The procedure that fits your requirement best is the first in this list:
procedure ShowMessage( const msg: string );
function MessageDlg( const msg: string; dlgType: tMsgDlgType; buttons: tMsgDlgButtons; helpctx: longint ): word;
function MessageDlgPos( ... x, y: integer ): word; //same args as MessageDlg
function InputBox( const aCaption, aPrompt, aDefault: string ): string;
function InputQuery( const aCaption, aPrompt: string; var value: string ): boolean;
The ShowMessage function just displays your message with a little OK button.
The MessageDlg displays a message with the desired icon and buttons.
The InputBox and InputQuery functions get a string from the user. The latter returns false if the user canceled.
type TMsgDlgType = (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom);
type TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mnNoToAll, mbYesToAll, mbHelp);
return values for MessageDlg:
mrNone mrAbort mrYes mrOk mrRetry mrNo mrCancel mrIgnore mrAll
If none of those work for you, create a new form that does what you want and set its border style to bsDialog. Display the form using the ShowModal function. Close the form and return a value by setting its ModalResult.
Good luck.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
You've made a syntax error somewhere. Please post your code.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
You need to read up on how to use procedures and functions.
Here's a nice tutorial .
Also, to use the MessageDlg function, you will need to put the Dialogs unit in your uses clause.
Good luck.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
That would work.
You would have to create a new form, and show it to display the message, and hide it to stop displaying the message. The trick is to let the user dismiss the form, which means responding to button presses or the [X] button or "Close" option of the window menu or if the user presses ENTER or ALT+F4. To do that stuff you'd have to display the form with showmodal, which I don't think you know enough to do easily.
If you are using Free Pascal and not the GNU Pascal (the Bloodshed Dev IDE works with both), then make sure you have the Dialogs unit in your uses clause:
uses Windows, SysUtils, <strong>Dialogs</strong>, Messages;
and to display a message use: showMessage( 'Hello world!' );
This displays a popup with the message and an OK button.
Or use: messageDlg( 'Hello world!', mtCustom, [], 0 );
to display the dialog without buttons. (I have never tried to show one without buttons. It may or may not work. Either way, you will still be able to click the [X] button or press ESC to terminate the dialog.)
Hope this helps. (And please read-up like I asked.)
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
Most older HLLs make a distinction between a function and a procedure. One returns a value, the other does not.
In C and C++, a procedure is declared by returning void (that is, it doesn't return anything):
void my_proc()
and, of course, a function: int my_func()
In Pascal, they are: procedure my_proc;
and function my_func: integer;
Here's an example:
function intpow( base, exponent: integer ): integer;
// Raises 'base' to the 'exponent' power
// and returns the result.
begin
if exponent < 0
then result := 0
else begin
result := 1;
while exponent > 0 do
begin
result := result *base;
dec( exponent )
end
end
end;
Using this function, I can calculate any non-negative exponent that fits in an integer:
intpow( 2, 0 ) --> 1
intpow( 2, 1 ) --> 2
intpow( 2, 2 ) --> 4
intpow( 2, 3 ) --> 8
etc.
Did this help? Or did I misunderstand you?
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229