Recent

Author Topic: Not blocking ShowMessage  (Read 5281 times)

Shebuka

  • Sr. Member
  • ****
  • Posts: 422
Not blocking ShowMessage
« on: May 08, 2012, 01:08:53 pm »
Hi,
is there a non blocking ShowMessage? Or i need to do it myself?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8273
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Not blocking ShowMessage
« Reply #1 on: May 08, 2012, 03:17:29 pm »
Do it yourself, well... what do you want to achieve anyway? ShowMessage is intended for simple message view. I believe you'll need something more complex if it's non-blocking.

Shebuka

  • Sr. Member
  • ****
  • Posts: 422
Re: Not blocking ShowMessage
« Reply #2 on: May 08, 2012, 03:47:55 pm »
I need a simple Form that show to user a message, but one that don't block the normal flow of the code execution.

However i realize that ShowMessage allocate resources and if the procedure that has called it is not blocked and reach the end, without a garbage collector it's difficult to avoid memory leaks...

Hmm, maybe i can create a class that manage a list of such forms, with more options, like auto close timers and callback events...

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Not blocking ShowMessage
« Reply #3 on: May 08, 2012, 03:54:10 pm »
What's about this?
Quote
uses Dialogs;
with CreateMessageDialog('Hello World',mtConfirmation,[mbYes,mbNo]) do
  Show;
Lazarus 1.7 (SVN) FPC 3.0.0

Shebuka

  • Sr. Member
  • ****
  • Posts: 422
Re: Not blocking ShowMessage
« Reply #4 on: May 08, 2012, 04:36:48 pm »
What's about this?
Quote
uses Dialogs;
with CreateMessageDialog('Hello World',mtConfirmation,[mbYes,mbNo]) do
  Show;

It's kind of working, if i click on Ok button (with mtInformation, [mbOk]) nothing happens and i need to close it with 'x'

And, does it lead to memory leak not assign the result of CreateMessageDialog?

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Not blocking ShowMessage
« Reply #5 on: May 08, 2012, 04:44:23 pm »
CreateMessageDialog could be hacked to work the way you want.

1. First to get rid of memory leaks assign an OnClose event to the returned TForm and set the CloseAction to caFree.

2. The buttons created are meant for dialogs, IOW: when a button is pressed it simply sets the ModalResult of the form, showmodal then would check this and close.  So you could use a Timer to check when the ModalResult is no longer mrNone and close the form.

Shebuka

  • Sr. Member
  • ****
  • Posts: 422
Re: Not blocking ShowMessage
« Reply #6 on: May 08, 2012, 05:55:24 pm »
Ok, it's clear to me now how i can use it :) thanks.

But still i think i will need to create a custom one... the CreateMessageDialog form is clearly not following the widget design...

See comparison on Mac OS X Carbon.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Not blocking ShowMessage
« Reply #7 on: May 08, 2012, 10:15:14 pm »
I would simply make a new TForm to act as a dialog. But also if you make TThread, which execute contains ShowMessage(), it shouldn't interrupt any of your code flow.

mas steindorff

  • Sr. Member
  • ****
  • Posts: 444
Re: Not blocking ShowMessage
« Reply #8 on: May 09, 2012, 01:12:49 am »
I would simply make a new TForm to act as a dialog. But also if you make TThread, which execute contains ShowMessage(), it shouldn't interrupt any of your code flow.
What happens if you try to end the main app when a ShowMessage is showing (and has the tthread locked)?  then there is yet more code to add to close a locked tthread. 
I vote for the TForm  :)
windows 7/10 - laz 2.0 / 1.2.6 general releases

Shebuka

  • Sr. Member
  • ****
  • Posts: 422
Re: Not blocking ShowMessage
« Reply #9 on: May 10, 2012, 12:15:42 pm »
I'v gone hard way and tried to modify promptdialog.inc to a separate customdialog.pas, it was a pain... even if i incuded in uses clause all what is used dy dialogs and dialogs itself, my customdialog can't find many of functions and constats that were user in promptdialog.inc, why? (i'v redefined them)
After i'v managed to create it i start a modification to port it to more OS X look and feel integrating it with OnClose KpjComp suggestion and an TDialogButtonClick event that can be assigned to send various Button Click events (also 'x' click and 'esc' press), also you can load any dialog icon you want in it, but not GetDialogIcon, seems that assign is not working well, or i'v coded something wrong...

It can be converted to be a part of Dialogs unit if anyone need it (but need more work to deliver crossplatform widget look)

Result: (first is carbon, second my lcl customdialog)
« Last Edit: May 10, 2012, 12:22:42 pm by Shebuka »

 

TinyPortal © 2005-2018