Recent

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

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #15 on: November 26, 2010, 07:55:00 pm »
Ok so I create a new form and unit, named showmsg.pas. I setup everything, but how do I use or where do I put this procedure:

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;

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #16 on: November 26, 2010, 08:00:05 pm »
For example:

Code: [Select]
ShowTheMessage('Title', 'Message', 1000);

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #17 on: November 26, 2010, 08:03:41 pm »
OK, I know that, use Dialogs,...,showmsg.

What am asking is where do I put the ShowTheMessage procedure.


captian jaster

  • Guest
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #18 on: November 26, 2010, 08:06:26 pm »
OK, I know that, use Dialogs,...,showmsg.

What am asking is where do I put the ShowTheMessage procedure.


Where ever you're trying to declare it..
For instance, if you want it to come up when you start the application  put the procedure in the "FormCreate" part

Code: Pascal  [Select]
  1. Procedure TForm1.FormCreate(Sender: TObject)
  2. begin
  3.    ShowThenMessage('Title','Message',1000);
  4. end;
  5.  
;D

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #19 on: November 26, 2010, 08:13:59 pm »
No, you don't get it, not how or where to call the procedure when I need it, where to put the actual procedure.

I created the new form, named it formMsg, created a label, called Msg, but I'm getting errors:

Code: [Select]
pigutils.pas(53,31) Error: Identifier not found "poScreenCenter"
pigutils.pas(54,35) Error: Identifier not found "fsSystemStayOnTop"
pigutils.pas(56,16) Error: Identifier not found "Application"
pigutils.pas(58,16) Error: Identifier not found "Application"
pigutils.pas(423,39) Hint: Local variable "S" does not seem to be initialized
pigutils.pas(428) Fatal: There were 4 errors compiling module, stopping

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #20 on: November 26, 2010, 08:16:36 pm »
You need Controls and Forms on uses section of that unit.

Don't put ShowTheMessage procedure on showmsg unit, but on the unit which will call it.
« Last Edit: November 26, 2010, 08:20:23 pm by typo »

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #21 on: November 26, 2010, 08:23:09 pm »
Yes sure, I get it, but how am I suppose to build the overall thing and use it in my app?
make a form; put a label, timer and a button;

invoke it like this (you can wrap these lines into a function):

Code: [Select]
 MsgForm.Tag := 10; // in seconds
  MsgForm.Label1.Caption := 'aasdsa asd asd asd as dasd';
  MsgForm.ShowModal;

to make it work, double-click the timer and add this into the event handler:

Code: [Select]
   if Tag = 0 then
        Close
    else begin
        Tag := Tag - 1;
        OKButton.Caption := 'OK  (' + IntToStr(Tag) + ')';
        Exit;
    end

assign any modal result to the button;  assign this same handler to the form's OnShow event (in object inspector).

you can take care of minor tweaks.

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #22 on: November 26, 2010, 08:26:42 pm »
Ok, made it work, but it looks really ugly :)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #23 on: November 26, 2010, 08:29:11 pm »
Why?

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #24 on: November 26, 2010, 08:38:58 pm »
I don't know, coz it doesn't look like it suppose to be like that. Just is missing something....

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #25 on: November 26, 2010, 08:41:49 pm »
In which unit is ShowModal?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #26 on: November 26, 2010, 08:44:14 pm »
ShowModal is a method of TForm class.

You can improve a bit that procedure by removing formMessage from automatic creation and:

Code: [Select]
procedure ShowTheMessage(ATitle, AMessage :string; ADelay :integer);
begin
  Application.CreateForm(TformMessage, formMessage);
  with formMessage do
  begin
    try
      Caption := ATitle;
      Position := poScreenCenter;
      FormStyle := fsSystemStayOnTop;
      Show;
      Application.ProcessMessages;
      Label1.Caption := AMessage;
      Application.ProcessMessages;
      Sleep(ADelay);
    finally
      Free;
    end;
  end;
end; 
« Last Edit: November 26, 2010, 08:58:22 pm by typo »

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #27 on: November 26, 2010, 09:08:30 pm »
Ok it works, but badly. First of all, it takes time to create the "Windows" or "Form" when I use it.
Second, I still have on the small form the close button on the title bar, which doesn't work, have to wait for the sleep to stop so the form dies.
Also it works the first time, but not the second time. The second time there is no message (Label) anymore, the form is created, but thats it.

Code: [Select]
Procedure ShowTheMessage(ATitle, AMessage :string; ADelay :integer);
Begin
  Application.CreateForm(TformMsg, formMsg);
  with formMsg do
  begin
    try
      Caption := ATitle;
      Position := poScreenCenter;
      FormStyle := fsStayOnTop;
      Show;
      Application.ProcessMessages;
      Msg.Caption := AMessage;
      Application.ProcessMessages;
      Sleep(ADelay);
    finally
      Free;
    end;
  end;
end;

Also the mouse kind of invisible for couple of seconds when the form is "displayed" or "created".

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #28 on: November 26, 2010, 09:24:30 pm »
None of this happens on my test.

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #29 on: November 26, 2010, 09:29:49 pm »
Well it does in mine and its not very good.