LazReport: Allow Generate report from another thread, modified patch from wadman, issue #31748

(cherry picked from commit 7993dbc779)
This commit is contained in:
Jesus Reyes A 2021-08-01 19:13:18 -05:00
parent 5a27d59f4e
commit ef20dfd61f

View File

@ -1737,6 +1737,11 @@ end;
{$ENDIF} {$ENDIF}
function IsMainThread: boolean;
begin
result := GetCurrentThreadId=MainThreadId;
end;
function IsCustomProp(const aPropName: string; out aIndex: Integer): boolean; function IsCustomProp(const aPropName: string; out aIndex: Integer): boolean;
var var
i: Integer; i: Integer;
@ -8552,7 +8557,7 @@ var
while not b.DataSet.Eof do while not b.DataSet.Eof do
begin begin
Application.ProcessMessages; if IsMainThread then Application.ProcessMessages;
if MasterReport.Terminated then if MasterReport.Terminated then
break; break;
AddToStack(b); AddToStack(b);
@ -10053,7 +10058,7 @@ begin
if Assigned(FOnProgress) then if Assigned(FOnProgress) then
FOnProgress(Percent) FOnProgress(Percent)
else else
if fShowProgress then if fShowProgress and IsMainThread then
begin begin
with frProgressForm do with frProgressForm do
begin begin
@ -11121,7 +11126,7 @@ begin
DisableDrawing := True; DisableDrawing := True;
FinalPass := False; FinalPass := False;
if not Assigned(FOnProgress) and FShowProgress then if not Assigned(FOnProgress) and FShowProgress and IsMainThread then
begin begin
with frProgressForm do with frProgressForm do
begin begin
@ -11146,7 +11151,7 @@ begin
Exit; Exit;
end; end;
if not Assigned(FOnProgress) and FShowProgress then if not Assigned(FOnProgress) and FShowProgress and IsMainThread then
begin begin
{$IFDEF DebugLR} {$IFDEF DebugLR}
DebugLnEnter('DoPrepareReport SecondPass INIT'); DebugLnEnter('DoPrepareReport SecondPass INIT');
@ -11212,13 +11217,13 @@ procedure TfrReport.ExportBeforeModal(Sender: TObject);
var var
i: Integer; i: Integer;
begin begin
Application.ProcessMessages; if IsMainThread then Application.ProcessMessages;
for i := 0 to EMFPages.Count - 1 do for i := 0 to EMFPages.Count - 1 do
begin begin
FCurrentFilter.OnBeginPage; FCurrentFilter.OnBeginPage;
EMFPages.ExportData(i); EMFPages.ExportData(i);
InternalOnProgress(i + 1); InternalOnProgress(i + 1);
Application.ProcessMessages; if IsMainThread then Application.ProcessMessages;
FCurrentFilter.OnEndPage; FCurrentFilter.OnEndPage;
end; end;
FCurrentFilter.OnEndDoc; FCurrentFilter.OnEndDoc;
@ -11554,7 +11559,7 @@ begin
FPageNumbers:=PageNumbers; FPageNumbers:=PageNumbers;
FCopies:=Copies; FCopies:=Copies;
if not Assigned(FOnProgress) and FShowProgress then if not Assigned(FOnProgress) and FShowProgress and IsMainThread then
begin begin
with frProgressForm do with frProgressForm do
begin begin
@ -11662,7 +11667,7 @@ var
EMFPages.Draw(n, Printer.Canvas, Rect(0, 0, 0, 0)); EMFPages.Draw(n, Printer.Canvas, Rect(0, 0, 0, 0));
end; end;
InternalOnProgress(n + 1); InternalOnProgress(n + 1);
Application.ProcessMessages; if IsMainThread then Application.ProcessMessages;
isFirstPage := False; isFirstPage := False;
{$ifdef DebugLR} {$ifdef DebugLR}
DebugLnExit('PrintPage: DONE',[]); DebugLnExit('PrintPage: DONE',[]);