Recent

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

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #30 on: November 26, 2010, 09:32:04 pm »
Probably the same would happen with ShowMessage procedure.

You can take off Close button from system menu through property BorderIcons of frmMessage.
« Last Edit: November 26, 2010, 09:47:45 pm by typo »

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #31 on: November 26, 2010, 09:49:46 pm »
i wanted to type something smart, but with all the problems you are encountering on this simple task, i realized that it is easier to open lazarus, copy into it what i posted above myself, and then send you the zipped code...

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #32 on: November 26, 2010, 09:54:29 pm »
No possible to use T:\ kind of doesn't work in Linux, if you get my point.

Plus it is "maybe" possible the results you have I wont have. Im on Linux with gtk2, Im not sure how compatible is Win with Lin!?

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #33 on: November 26, 2010, 10:10:39 pm »
Ok, I will re-explain the situation, because maybe I wasn't that precise about it.
This app run on Linux and KDE. Until now I was using kdialog to generate some "info" when for example the user was using Search function.

Because search doesn't need an "approval" I can't use ShowMessage, so I need to use something which only informs that user that the search is happening and was using:

Code: [Select]
kdialog --passivepopup "Searching, please wait..."

but the issue with this, is that is started by a function in my app, called execute, which after some times end-ups creating zombies of "kdialog".

Here is the execute function:

Code: [Select]
procedure execute (command:string; var output:Tstrings);
const
  READ_BYTES = 2048;

Var
 Process :Tprocess;
   MemStream : TMemoryStream;
  n: LongInt;
  BytesRead: LongInt;
begin
try
Process := TProcess.create(nil);;
 Process.CommandLine :=  command;



 {Actually run the thing and catch the output}
  MemStream := TMemoryStream.Create;
  outPut := TStringList.Create;
  BytesRead := 0;

    Process.Options := [poUsePipes,poNoConsole];

  Process.Execute;

  while Process.Running do
  begin
    // make sure we have room
    MemStream.SetSize(BytesRead + READ_BYTES);

    // try reading it
    n := Process.Output.Read((MemStream.Memory + BytesRead)^, READ_BYTES);
    if n > 0
    then begin
      Inc(BytesRead, n);
    end
    else begin
      // no data, wait 100 ms
      Sleep(100);
    end;
  end;
  // read last part
  repeat
    // make sure we have room
    MemStream.SetSize(BytesRead + READ_BYTES);
    // try reading it
    n := Process.Output.Read((MemStream.Memory + BytesRead)^, READ_BYTES);
    if n > 0
    then begin
      Inc(BytesRead, n);
    end;
  until n <= 0;
  MemStream.SetSize(BytesRead);
  OutPut.LoadFromStream(MemStream);
  MemStream.Free;
 Process.Free;
except
      debugln('Could not execute: '+Command);
end;
end;

procedure execute (command:string);
{This version just launches without waiting or capturing output}
Var
 Process :Tprocess;
begin
try
Process := TProcess.create(nil);;
 Process.CommandLine :=  command;
  Process.Options := [poNoConsole];
  Process.Execute;
 Process.Free;
except
      debugln('Could not execute: '+Command);
end;
end;

Now I would like a function/procedure which send this message, if possible to KDE notification and appears at the taskbar.

The procedure that you guys mentioned is ok, but is slow and has a lot of issues, ok, maybe it's me, because I haven't use pascal/lazarus in like 10 years :)

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #34 on: November 26, 2010, 10:20:48 pm »
Check the attachment, its an example of what I mean.

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #35 on: November 26, 2010, 11:23:44 pm »
No possible to use T:\ kind of doesn't work in Linux, if you get my point.

no i don't.  it is fully platform independent.  you just don't want to spend more than a second on things.

fix or delete the config file from the archive.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #36 on: November 26, 2010, 11:40:42 pm »
Try attached.

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #37 on: November 26, 2010, 11:47:30 pm »
Can't build it:


Unit2.pas(44,1) Error: resource compiler not found, switching to external mode

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #38 on: November 27, 2010, 12:26:49 am »
Try another one.

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #39 on: November 27, 2010, 12:30:49 am »
LOL! Same issue :)

Im must be the most unlucky lazarus user ever :)

Told u win stuff wont work well on linux stuff!

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #40 on: November 27, 2010, 12:39:25 am »
Copy the files to a project made on your computer.
« Last Edit: November 27, 2010, 12:41:47 am by typo »

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #41 on: November 27, 2010, 12:42:56 am »
I get the idea of it, but I can't use ur idea in my app, at least not in the same way, anyway.

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #42 on: November 27, 2010, 11:45:04 am »
So nothing?

jinx

  • New Member
  • *
  • Posts: 23
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #43 on: November 27, 2010, 07:19:55 pm »
OK, lets forget about creating a new form, but I would like to fix one thing when using "kdialog". Note this is for Linux/KDE, not windows.

Here is whats happening when using "execute" procedure:

Code: [Select]
kongoni  11353 25958  0 19:15 ?        00:00:00 [kdialog] <defunct>
kongoni  11638 25958  0 19:15 ?        00:00:00 [kdialog] <defunct>
kongoni  12341 25958  2 19:16 ?        00:00:00 [kdialog] <defunct>

For some reason, until my pass is not killed those zombies are not going away, plus they will be many more depending on the apps usage.
So can anyone check the procedure execute which I wrote in a previous post?
« Last Edit: November 27, 2010, 07:22:31 pm by jinx »

garlar27

  • Hero Member
  • *****
  • Posts: 618
Re: Similar function in Lazarus as ShowMessage, but with delay not "OK" button.
« Reply #44 on: November 29, 2010, 01:28:07 pm »
Told u win stuff wont work well on linux stuff!

   Don't hesitate! We all know that windows' stuff don't work on linux but, FPC and Lazarus are cross platform and we share the same code between different OSs.
   So the first attempt is to do it the cross-platform way (a form on scrren center with a text and a caption and no buttons) which can be implemented in various ways and would need a little tweak to achieve the desired "flavor".
   but if you if you are having problems to fit your needs and you are short of time you can use the ugly, and muddy shortcut by executing an external app or an OS command with:

Code: Pascal  [Select]
  1. ExecuteProcess(Application.Location, 'kdialog --passivepopup "Searching, please wait..."');

You can find more info about "ExecuteProcess" on the Wiki