Problem when previewing QuickReport

I am using Borland Delphi 2006 and QuickReport 4 to try to preview a report. Sometimes the report preview goes blank. When the form is closed delphi throws an exception saying "Win32 Error: Code 1400. Invalid Window Handle".
If I try to preview the report again I receive the message "A compoent namned qrstandardpreview already exists ".
The only way to make any QuickReport in the program to work is to close the program and the start it again.

Have someone had the same problem and how did you solve it? Is there any use to upgrade to QuickReport 5?
My application runs on a Microsoft Vista Business OS but I do not know if this is of importance.

//Thanks!
ture68Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bokistCommented:
Some years ago I fought with similar problem.
I solved it with PreviewModal instead of Preview.
0
ture68Author Commented:
Unfortunately I am already using PreviewModal
0
bokistCommented:
Perhaps this will help :

         try
            QuickRep1.PreviewModal;
         finally
            QuickRep1.QRPrinter.Free;
         end;
         QuickRep1.QRPrinter := nil;
0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

ture68Author Commented:
My code look like this, please change it to your suggestion.

procedure ShowNotes(const APerson: TemPerson; const AUser: TemUser);
var
  formQRNotes: TFormQRNotes;
begin
  formQRNotes := TFormQRNotes.Create(Application);
  try
    formQRNotes.FPerson := APerson;
    formQRNotes.FUser := AUser;
    //Init will be automatically called
    formQRNotes.QuickRepNotes.PreviewModal;
  finally
    formQRNotes.Free;
  end;
end;
0
ture68Author Commented:
Below you will find the complete report. Note that I am also using the global flag PrintMetafileFromPreview.

procedure ShowNotes(const APerson: TemPerson; const AUser: TemUser);
var
  formQRNotes: TFormQRNotes;
begin
  formQRNotes := TFormQRNotes.Create(Application);
  try
    formQRNotes.FPerson := APerson;
    formQRNotes.FUser := AUser;
    //Init will be automatically called
    formQRNotes.QuickRepNotes.PreviewModal;
  finally
//    formQRNotes.Release;
    formQRNotes.Free;
  end;
end;

{ TFormQRNotes }

procedure TFormQRNotes.QuickRepNotesBeforePrint(
  Sender: TCustomQuickRep; var PrintReport: Boolean);
begin
  PrintMetafileFromPreview := True;
  QuickRepNotes.PrinterSettings.PrintMetaFile := True;
  Init;
end;

procedure TFormQRNotes.Init;
begin
  FFirstEmpty := True;
  FCurrentIndex := 0;
  FNotes := FPerson.Notes;
  //do something
end;

procedure TFormQRNotes.QuickRepNotesNeedData(Sender: TObject;
  var MoreData: Boolean);
begin
  if FNotes.Count < 1 then
  begin
    MoreData := FFirstEmpty;
    FFirstEmpty := False;
  end
  else
  begin
    if FCurrentIndex >= FNotes.Count then
    begin
      MoreData := False;
    end
    else
    begin
      //do something
      FCurrentIndex := FCurrentIndex +1;
      MoreData := True;
    end;
  end;
end;
0
bokistCommented:

For what purposes you are using  PrintMetafile ?
0
ture68Author Commented:
Without the use of PrintMetaFile the preview differs from printout. Pagination and memo-field were corrupted during printout. Also when setting page interval the printout was different compared to the same page when printing all pages.
By sending the existing preview to the printer this was avoided and also give a faster printout because the program did not regenerete the complete report again before printing the report.
0
Geert GOracle dbaCommented:
some printers give errors with metafile printing

it is possible that you need to disable the advanced printing functions in the printer driver

it is also possible that the printer gives error with spooling (or meta spooling)
0
ture68Author Commented:
How can I disable the advanced printing function in the printer driver? Properties on the printer itself or changing drivers?

How do I catch printer errors with spooling?
0
senadCommented:
It seems your opening and closing of the queery that qreport uses is not fired properly.I had similar issue once.After preview I forgot to unload the queery and had blank report.Now this goes for the table also....
Check !
0
senadCommented:
why dont you use simple boolean recordprinted (true/false) ?
0
ture68Author Commented:
Hi sorry for the late answer I have been on vacation.
I have now checked that the query is unloaded as it should.

What do you mean by setting recordprinted to true or falste, please give me an example.
0
senadCommented:
This is what you should have on every quick report :
global variable shoud be set to recordprinted:boolean;

procedure TForm8.QuickRep1NeedData(Sender: TObject; var MoreData: Boolean);
begin
MoreData := not RecordPrinted;
end;

procedure TForm8.ColumnHeaderBand1AfterPrint(Sender: TQRCustomBand;
  BandPrinted: Boolean);
begin
RecordPrinted := True;
end;

procedure TForm8.ColumnHeaderBand1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
begin
RecordPrinted := False;
end;

procedure TForm8.QuickRep1BeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
begin
RecordPrinted := False;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rocio carCommented:
no se si aun les sirva, pero lo solucione usando un prepare antes de hacer un previewmodal, o solo hacer preview, cuando uso solo el previewmodal es que me manda el error.
0
Geert GOracle dbaCommented:
That's patience. Waiting 7 years to comment :)
1
senadCommented:
Google translation of his comment (sorry, no habla espagnol):
I do not know if it still works for me, but I solve it using a preparation before doing a modal preview, or just previewing, when I use only the modal preview, it sends me the error.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.