Hello.
This is my component to work with additional threads for Delphi & Lazarus.
Using them is very easy.
Drop a TWCThread on the form and add a few tasks.
In the task you need to write a method OnExecute which will be executed in a different thread.
Each task is a message flow. All tasks will run in the start order.
Components tested on Ubuntu 14 and 16 LTS, Windows 7, WinCE, Lazarus 1.6/1.7, Delphi 7/XE2.
The archive contain a small demos.
[updated 26 nov 2016]
Rewrite code for memory leaks.
Added two new demo:
1. Small& simple update system from local server (share) to local computer. It uses two threads: one for reading and one for writing (for speed). After update auto run main file. Update settings are specified in ini file. It should work on Linux, I have not tested it.
[Main]
# caption for run.exe
Name=SomeExe
# main file, will run after update
Run=SomeExe.exe
# cmdLine for main file
Parameters=
# count of files, see above
Count=1
#always update/overwrite
Overwite=1
[File1]
# full path of source file
From=run.exe
# short (local dir) of dest file
To=run.tmp
2. Background lazReport generate and printing.
For the correct execution of this demo need to make some corrections in LR_CLass.pas of lazReport package file.
It is necessary to exclude the call Application.ProcessMessages.
Add option to a report item roMultithread:
TfrReportOption = (roIgnoreFieldNotFound, roIgnoreSymbolNotFound, roHideDefaultFilter,
roDontUpgradePreparedReport, // on saving an old prepared report don't update to current version
roSaveAndRestoreBookmarks, // try to save and later restore dataset bookmarks on building report
roPageHeaderBeforeReportTitle, // PageHeader band is printed before ReportTitle band
roMultithread // this
);
Add protected method procedure DoApplicationProcessMessages to TfrReport class;
procedure TfrReport.DoApplicationProcessMessages;
begin
if (not (roMultithread in Options)) or (csDesigning in ComponentState) then
Application.ProcessMessages;
end;
And then replace all the code
Application.ProcessMessages;
with the following code
if Assigned(CurReport) then
CurReport.DoApplicationProcessMessages;
Thats all, your report ready to run and print in background!
It is enough to turn on [roMultithread] and off ShowProgress.
Archive contain modified version of LR_CLass.pas from latest version (from github).
[updated 28 nov 2016]Unfortunately demo report failed to run under the nix.
In Windows7 it works fine.
---
Some fixes.
---
This component is published on
https://github.com/wadman/wthread/