* * *

Author Topic: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.  (Read 23027 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: 5742
  • 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: 2340
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: 1174
Just create a tiny wrapper function for it.
You can make it as simple or complicated as you want.
E.g.
Code: (pascal) [Select]
procedure MyShowMessage(Const Fmt : String; const Args : Array of const);
begin
  ShowMessage(format(Fmt,Args))
end;

//...

MyShowMessage('What''s up number %d', [1000]);
Win8 Prof (Win64); Lazarus 1.2.2 (#44758; win32 and win64)

typo

  • Hero Member
  • *****
  • Posts: 2340
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: 2340
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: 2340
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: 2340
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: 2340
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 »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus