Recent

Author Topic: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.  (Read 40551 times)

jinx

  • New Member
  • *
  • Posts: 23
Hello, I'm building a small app in lazarus in which I need a function/procedure similar to ShowMessage, but instead of give me "OK", it will exit itself in a certain amount of time (some delay variable).

Also, is there a function/procedure similar to what kdialog dose:

Code: [Select]
kdialog --passivepopup "Test ..."

P.S. Im building this for KDE, if it helps...

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Quote
I need a function/procedure similar to ShowMessage, but instead of give me "OK", it will exit itself in a certain amount of time (some delay variable).
There's none ATM. You need to create a form with TTimer and show it as modal form.

jinx

  • New Member
  • *
  • Posts: 23
Ok, how?! A form I can create, add a timer to it also, but the rest not really!

typo

  • Hero Member
  • *****
  • Posts: 3051
You could not use a Timer or ShowModal, simply set you FormStyle to fsSystemStayOnTop and call it like this:

Code: [Select]
  FormMessage.Show;
  Application.ProcessMessages;
  Sleep(1000);
  FormMessage.Hide;

jinx

  • New Member
  • *
  • Posts: 23
I need something that modifies, I mean the message in it. Like calling a function:

ShowMessage('I need help! :)', 1000);

1000 would be the time out, lets say.

eny

  • Hero Member
  • *****
  • Posts: 1634
Just create a tiny wrapper function for it.
You can make it as simple or complicated as you want.
E.g.
Code: Pascal  [Select][+][-]
  1. procedure MyShowMessage(Const Fmt : String; const Args : Array of const);
  2. begin
  3.   ShowMessage(format(Fmt,Args))
  4. end;
  5.  
  6. //...
  7.  
  8. MyShowMessage('What''s up number %d', [1000]);
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

typo

  • Hero Member
  • *****
  • Posts: 3051
No, he needs something like this:

Code: [Select]
procedure ShowTheMessage(ATitle, AMessage :string; ADelay :integer);
begin
  with formMessage do
  begin
    Caption := ATitle;
    Position := poScreenCenter;
    FormStyle := fsSystemStayOnTop;
    Show;
    Application.ProcessMessages;
    Label1.Caption := AMessage;
    Application.ProcessMessages;
    Sleep(ADelay);
    Close;
  end;
end; 

jinx

  • New Member
  • *
  • Posts: 23
So with that simple procedure it will actually work?!

Also is there a possibility of using the notification from KDE? Send messages to KDE notification?

typo

  • Hero Member
  • *****
  • Posts: 3051
You need to create formMessage with a Label with WordWrap set to True.

jinx

  • New Member
  • *
  • Posts: 23
How to create a formMessage?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #10 on: November 26, 2010, 07:05:11 pm »
On the IDE File menu choose New Form.

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #11 on: November 26, 2010, 07:09:12 pm »
Yeah, but thats now formMessage, its just a form.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #12 on: November 26, 2010, 07:14:33 pm »
Save it as formMessage, put a label on it, set its size and position, AutoSize to False and its WordWrap to True.
« Last Edit: November 26, 2010, 07:23:55 pm by typo »

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #13 on: November 26, 2010, 07:38:26 pm »
Yes sure, I get it, but how am I suppose to build the overall thing and use it in my app?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #14 on: November 26, 2010, 07:40:58 pm »
Add formMessage's unit to your uses section.
« Last Edit: November 26, 2010, 07:43:49 pm by typo »

 

TinyPortal © 2005-2018