954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to make a popup window

Hello DaniWeb. I'm new to this site and will just have to say some words before asking my question. I'm Loyen and I am 14 years old and lives in Sweden. I've just started on an upper secondary school about IT and there I'm going one class that's called "programming" there we're learning the basics in Pascal.

Now, I'm really interested in this, and just wanted to know, how do I do a basic popup window that just gives you a message? Can I make one that has no buttons just a clean window without any "minimazers, closers" and all?

Write it here. :)

Thank you all for your time and hopefully somebody knows how to do a basic popup window.

//Loyen

Loyen
Light Poster
47 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Loyen,

Are you using Delphi for this class?

If so, there are several ways to go about doing this, although I would suggest having at least an "OK" button for closing the pop-up window.

One approach, in Delphi, would be to use a MessageDlg.

MessageDlg('Test with no buttons',mtInformation,[],0);


A question for you to consider is, if you create a pop-up windowthat has no buttons just a clean window without any "minimazers, closers" and all, how do you plan to close the window and exit the program?

RDWilson2
Newbie Poster
15 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

I didn't plan to close it. ^^
through taskbar if I wanted some time though. :P

No, we don't use delphi. We are just using Pascal. :/

Loyen
Light Poster
47 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Which Pascal are you using?

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

Regrettably, it has been far too many years since I worked in base-level Pascal. Sorry.

Also, it really depends on the implimentation of Pascal (i.e. the compiler) with which you are working.

RDWilson2
Newbie Poster
15 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

I work with the free Pascal version. (1.9.2)

Loyen
Light Poster
47 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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
 

Now.. How do I make it work and where should I write the message? xD.. don't really know cause we have pretty much just worked with console programs..

Loyen
Light Poster
47 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

If you use the

function MessageDlg( const msg: string; dlgType: tMsgDlgType; buttons: tMsgDlgButtons; helpctx: longint ): word;

approach and you do NOT want any buttons (which is still a most curious concept), you would write something like:

MessageDlg('your message goes here', mtInformation,[],0);

wherever you want it in your project and then, when that line is executed, it will pop up the message box.

RDWilson2
Newbie Poster
15 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Got this error?
J:\Pascal program\Message programs\Popup1\Popup.pas:5: parse error before `Begin'
J:\Pascal program\Message programs\Popup1\Popup.pas:7: module/unit `code' could not be compiled


Noticed that my program isn't free pascal.. it's called "Dev-Pascal" or something like that.. hmm..

Loyen
Light Poster
47 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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
 

program WindowsApp;
Uses
Messages, Windows

Begin


function MessageDlg( const msg: string; dlgType: tMsgDlgType; buttons: tMsgDlgButtons; helpctx: longint ): word;

approach and you do NOT want any buttons (which is still a most curious concept), you would write something like:

MessageDlg('your message goes here', mtInformation,[],0);

END.

Loyen
Light Poster
47 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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
 

Im not sure about FP but I know if they are compatible as Duaos mentioned... Then simply do something like:

Procedure TForm.FormCreate(Sender: TObject);
begin
label.caption := 'write what you want to here';
end;


Again, I dont know if that will work in FP. But if you can get that to work, then great! Then goto (if you have this) object inspector and remove anything you dont want there. click on the form itself first of course and then look for the minimize and close options in there.

I am probably way off base on what you need, but I am trying anyway. lol

squidd
Junior Poster
100 posts since Nov 2007
Reputation Points: 10
Solved Threads: 2
 

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
 

The pascal version is "Bloodshed Dev-Pascal".

bump

Loyen
Light Poster
47 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Also, I'm an BIG amateur on this.. I know how to do simple procedures which takes integers or char/string from the main program, make function that tells you sums of an addition or something like that and iterations, selections, types.. not more.. so this is overclass for me, but I want to learn.. also Duoas, I've read that guide before, but still don't understand the "function" in the code.. .

Loyen
Light Poster
47 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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
 

I know that one of them returns a value (the function does that, right?) and the other does not..

*back to the topic cause I only want to do a simple popup, buttons or not I don't care.

but if you look at your examples:
should it look like this?

[code=pascal]
program popupwindow;

uses Windows, SysUtils, Dialogs, Messages;

begin
showMessage( 'Hello world!' );

end.

Is that correct? Cause it doesn't work, and I tested the second "show message" you sended.. same thing

Loyen
Light Poster
47 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Hmm, I knew about that (but it got complicated at the program part but I know about functions and procedures (functions gives something back and procedures don't)

Back to the thing I wanted done, a popup windows with or without buttons

I've tried the things you wrote before but can't get it to work.. should it look like this:

program popupwindows;
uses Windows, SysUtils, Dialogs, Messages;

begin
showMessage( 'Hello world!' );

end.


is that it?

Cause it won't work :(

Loyen
Light Poster
47 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You