Recent

Author Topic: calling a form procedure from an outside procedure using paszlib  (Read 443 times)

ddev

  • New Member
  • *
  • Posts: 18
Hi everybody,

I have a very basic problem, but I cannot find an answer reading posts in this wonderful forum.

I have a LCL app that generates very big text files (up to 100GB!) and I use TZipper to compress them. As you can imagine it takes quite a long time to compress those files, up to one hour. So my problem is how to give the user a feedback about when the compression will end. For that I use TZipper events, specifically:

Code: Pascal  [Select][+][-]
  1. zip := TZipper.Create;
  2.  
Lazarus 3.4
FPC 3.2.2
Mac OS X 13.6.1 Ventura

cdbc

  • Hero Member
  • *****
  • Posts: 1830
    • http://www.cdbc.dk
Re: calling a form procedure from an outside procedure using paszlib
« Reply #1 on: July 02, 2024, 11:15:08 am »
Hi
Send a message to the form's 'Handle' via 'PostMessage' or 'SendMessage'.
"uses LCLIntf,LMessages;" // in both form-unit and your compression-unit
in compression unit:
const
  LM_COMPDONE = LM_USER + 5; // arbitrary number
...
  // when done compressing:
  "PostMessage(the-Handle-from-form,LM_COMPDONE,1,1);"
in form unit:
create a message handler in your form:
Code: Pascal  [Select][+][-]
  1.   TForm1 = class(TForm)
  2. ...
  3.   public
  4. ...
  5.     procedure LMCompDone(var Message: TLMessage); message LM_COMPDONE;
  6.   end;
  7.  
You somehow have to get the form's handle to the compression-unit and keep it safe there, till it's time to send the message...
That's a clean & easy way to communicate, should be thread-safe too...
HTH
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

 

TinyPortal © 2005-2018