5

I want to display message on PC which may not be attended. The user can read the message when he comes back.

Execution of my app must continue, so I need something non-modal. Before I starting code & creating new forms, I would like ask if there is something like `ShowMessage' which is non-modal.


[Update] Thanks for the feedback so far. I do know how to do it using a form, I just wondered if there something that would involve me writing less code. It seems not. I shall search the VCL component sites to see if someone has already inverted this particular wheel.

It looks like the short answer to my question is "no".

Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
  • 1
    It seems as if you are trying to do this in order to avoid anything from stopping your application from responding. Although this is possible, this is usually where you need to consider implementing at least one background thread to do whatever processing you need, and interact with your form safely, such as using synchronized events or message pumps. – Jerry Dodge May 14 '14 at 03:01
  • I just want to leave a sort of "while you were gone..." notice for the user & continue running. – Mawg says reinstate Monica May 14 '14 at 03:05
  • 3
    No -1 from me, but that type of window should never even be thought to be modal in the first place. You should clarify in your question what exactly you're showing in this dialog, because it doesn't sound like it should be a dialog at all, but just another form. – Jerry Dodge May 14 '14 at 03:07
  • 2
    @Jerry the question talks about non-modal dialogs – David Heffernan May 14 '14 at 06:15
  • 1
    Answer about flyout windows on stack: http://stackoverflow.com/questions/2105010/windows-7-style-notifications-flyouts-in-delphi – Pieter B May 14 '14 at 06:57
  • @David Yes, I can read that. The question's been edited since my comments. Still what's wrong with what I'm saying? – Jerry Dodge May 14 '14 at 14:21
  • @JerryDodge Then I don't understand your comment. You said "but that type of window should never even be thought to be modal in the first place". Since the question asks about non-modal windows, the asker is not thinking of a modal window. – David Heffernan May 14 '14 at 14:25
  • @David From what I understand, the original plan was to use `MessageDlg` but since it puts the application in a modal state, Mawg was looking for an equivalent ready-to-use non-modal dialog. Based on what is actually being displayed in this dialog (still fairly unclear), it should have never been modal in the first place. – Jerry Dodge May 14 '14 at 14:29
  • @JerryDodge The question doesn't say that and never has done. Mawg just asks for a way to create a simple non-modal dialog/form without having to build the form manually. – David Heffernan May 14 '14 at 14:38

4 Answers4

11

From what I know - the answer is "no".

There's not much use of such non-modal message box because indeed, message box implies that program can not continue without getting users feedback (Yes/No/Ok/Cancel) or verifying user read it (Ok).

Without knowing other details, I guess you need a log, not a pile of unhandled message boxes. Worst case scenario, how many such messages do you expect to pile up if LAN breaks down, or something like that, 5, 20, 1000?

Create another form with a TMemo in it and when your program needs to report something - display the form and add the string to that Memo. So when the user returns back, he sees that log.

Making a custom TForm with a TMemo or TLabel on it and a public procedure AppendLog(aMsg: string); is a matter of 10min, much shorter than what you will spend on searches and definitely a better fit to your usage scenario.

Kromster
  • 7,181
  • 7
  • 63
  • 111
  • Right way to go, but I wouldn't use a memo, because the user may choose to "accept" certain ones. Similar to how Microsoft Outlook reminders are reported in a single window. We barely know anything about what types of messages will be actually shown here. – Jerry Dodge May 14 '14 at 05:21
  • 2
    @JerryDodge: "to "accept" certain ones" Please explain this one. What I'm implying, is that Mawg can design that form the way he needs, after all, he wanted a lone MessageBox for a start. With a custom form he can keep it as simple as a borderless TMemo, or go ta a full-blown Grid-Tree-ScrollBox with bells and whistles. – Kromster May 14 '14 at 05:27
  • Well if you've ever used Outlook to keep track of calendar reminders, there's a common window which shows only once when there's at least one or more reminders, and each reminder listed can be either dismissed or snoozed for a given period of time, in which it appears again. The question doesn't indicate whether or not this is the case, it only speaks of a non-modal dialog to display "while you were gone" message(s). – Jerry Dodge May 14 '14 at 05:29
  • 3
    I second this answer. I use a custom log form class that handles messages in a grid, and also shows stats regarding the background operation which is running. But you can put any type of component and UI on this type of form, and it is not a complex solution. – Frazz May 14 '14 at 05:33
6

For only showing a notification message to user without interupting application workflow what you should use are Windows Balloon Tips. These are those Balloon shaped messages which pop-up above system tray. Easiest way of showing them with Delphi is to use TTrayIcon (available since Delphi XE if I'm not mistaken) http://docwiki.embarcadero.com/CodeExamples/XE5/en/TTrayIcon_(Delphi) http://docwiki.embarcadero.com/Libraries/XE5/en/Vcl.ExtCtrls.TTrayIcon

Default behavior of Balloon tips is that they stay visible when user is away from PC and only hide some time after user activity. So this almost guarante that user will see the message. You can set the time for this Balloon Tip to be visible. You can create a custom event which will be fired when user clicks on Balloon Tip (presenting some choice to the user for instance). Another advantage of Balloon Tips is that they don't popup when you are using any FullScreen aplications like games, movie players, etc. They will popu as soon as you leave the FullScreen mode of any of those applications.

SilverWarior
  • 7,372
  • 2
  • 16
  • 22
5

Take a look at the function CreateMessageDialog in unit Vcl.Dialogs. This returns a the standard VCL MessageDialog form which you can manipulate, if necessary, and then show, modal or normally, as you wish.

Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
  • 6
    Be warned that if you don't show 'modal' any form, modal result of buttons in that form will have no effect. IOW, you can't close a form returned by `CreateMessageDialog` by clicking its buttons, if you don't show it modal. – Sertac Akyuz May 14 '14 at 09:07
  • 1
    Correct, but you can attach handlers to the buttons that close the dialog and that set the "modal" result. – Rudy Velthuis May 14 '14 at 12:19
  • 1
    Also, if you show non-modal, you should consider adding a TCloseEvent handler to set CloseAction to caFree when it is closed. – Disillusioned May 27 '14 at 12:01
1

You should look at JvDesktopAlert from the JVCL. It provides similar functionality to the TTrayIcon BallonHint, but is more configurable and can show multiple (stacked) windows. It is supported at least as far back as Delphi 7.

crefird
  • 1,590
  • 11
  • 17