Canceling already started but not yet shown report

edited September 2006 in FastReport 3.0
First, let's describe the problem:

I have a report dialog form where I call for the report.
Database component's in the report are:
- ADODatabase
- ADOQuery //executes stored procedure

On the click event of the "Print" button I call for so called "busy" form
which is displayed until the report has been shown on the screen.

Report dialog form code:
procedure TfrmReportFormDlg.pbPreviewClick(Sender: TObject);
var qMaster : TfrxADOQuery;
begin
  try
  OpenBusyForm;
  qMaster := Report.FindObject('qMaster') as TfrxADOQuery;
  TADOQUery(qMaster.DataSet).ExecuteOptions := [eoAsyncExecute];
  Application.ProcessMessages;
  Report.OnProgress := rep1Progress;
  Application.ProcessMessages;
    try
      Report.PrepareReport;
    except
    end;

    if dmSWDatabase.report_terminate = False then
    Report.ShowPreparedReport;
 
  finally
  CloseBusyForm;
  end;

end;

procedure TfrmReportFormDlg.rep1Progress(Sender: TfrxReport;
  ProgressType: TfrxProgressType; Progress: Integer);
begin
Sender.Terminated := dmSWDatabase.report_terminate;
end;





On that busy form I have a button "Cancel report".

Busy form code:
procedure TfrmBusy.BitBtn1Click(Sender: TObject);
begin
dmDatabase.report_terminate := True; //global variable
Application.ProcessMessages;
end;

procedure TfrmBusy.FormCreate(Sender: TObject);
begin
dmSWDatabase.report_terminate := False;
end;


In the unit frxDBSet I have added this:

frxDBDataSet code:
procedure TfrxDBDataSet.Open;
begin
  if FInitialized then
    Exit;

  FInitialized := True;
  FDS.Open;

// my inserted code
  if FDS is TADOQuery then begin
        while (TADOQuery(FDS).RecordsetState = [stConnecting]	)
          or (TADOQuery(FDS).RecordsetState = [stExecuting]	)
        do begin
          sleep(100);
          Application.ProcessMessages;
          Report.Terminated := dmSWDatabase.report_terminate;

            if Report.Terminated then begin
              TADOQuery(FDS).Parameters.Command.Cancel;
              Abort;
            end;
        end;       
  end;
// end of my inserted code

  AfterOpen(nil);
  if (RangeBegin = rbCurrent) or (RangeEnd = reCurrent) then
    FBookmark := FDS.GetBookmark else
    FBookmark := nil;

  inherited;
end;

procedure TfrxDBDataSet.First;
begin
  if not FInitialized then
    Open;
  if RangeBegin = rbFirst then
  begin
    FDS.First;  // this is the line after which the execution of the stored procedure is gone 
  end
  else
    FDS.GotoBookmark(FBookmark);
  FEof := False;
  inherited First;
end;




What happens is this:

If the stored procedure has any messages (through the query analizer) in the result the busy form will never endingly stayed on the screen and the report will never be shown.
If the messages in the stored procedure (for example PRINT 'some value' or ("1 row(s) affected") are commented then the report will be generated successfully.

Does anyone have any suggestion how I can keep messages and get report? Thanks in advance.


P.S. Sorry if my English isn't very good and for the long post.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.