Is Crystal Report with Output = toWindow from Delphi background thread possible?
is it possible to execute a crystal report (TCrpe component) from a Delphi non VCL main thread when Output = toWindow?
- I execute reports from a background thread, and when Output is toPrinter or toExport, everything is fine.
- I know that creating forms in a Delphi non VCL main thread generally is a bad idea.
- When a Crystal Report is executed, and Output=toWindow, the component creates the output window on its own. So I cannot prevent that the window is created by the background thread.
- So is there a clean way to execute the report in a background thread, and display the result in a cleanly created form?
- Version: Crystal11VCL7
The following code does not work:
procedure TMyThread.Exec开发者_如何学JAVAute;
var
cr: TCrpe;
begin
inherited;
cr:= TCrpe.Create(nil);
cr.ReportName:= 'C:\TestReport.rpt';
cr.Output:= toWindow;
cr.WindowParent:= Form1; //This is the main form
cr.Execute;
end;
- It seems like the report will be created and immediately destroyed afterwards.
- When I enter a message loop right after cr.Execute (
while true do Application.ProcessMessages;
- which is obviously a very bad idea), the report window is shown nicely.
Any idea, how to do it right? Or is it simply not possible? Thanks!
I haven't had any experience with Crystal for many years (thank goodness) but in the absence of any other reply I would consider approaching the problem from a different angle.
What I do is let the report form be created in the main thread - because, as you've said, it's not a good idea to do the VCL stuff in the background - but I generate all report /data/ in a background thread. Once the data is loaded then the thread signals the main form (or whatever) via a windows message and the report goes and connects up to the dataset/datasource.
Initially I display a blank label over the client area of the report window with a message saying something like 'Report loading...' then once the message is received it hides the label and attaches the data. Works really well here and keeps the UI responsive.
精彩评论