Solved

Problem when previewing QuickReport

Posted on 2009-07-01
17
2,619 Views
Last Modified: 2016-11-16
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!
0
Comment
Question by:ture68
  • 6
  • 4
  • 3
  • +2
17 Comments
 
LVL 6

Expert Comment

by:bokist
ID: 24756724
Some years ago I fought with similar problem.
I solved it with PreviewModal instead of Preview.
0
 

Author Comment

by:ture68
ID: 24758528
Unfortunately I am already using PreviewModal
0
 
LVL 6

Expert Comment

by:bokist
ID: 24761034
Perhaps this will help :

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

Author Comment

by:ture68
ID: 24761377
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
 

Author Comment

by:ture68
ID: 24761435
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
 
LVL 6

Expert Comment

by:bokist
ID: 24761495

For what purposes you are using  PrintMetafile ?
0
 

Author Comment

by:ture68
ID: 24761542
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
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 24768864
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ture68
ID: 24847255
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
 
LVL 22

Expert Comment

by:senad
ID: 24891791
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
 
LVL 22

Expert Comment

by:senad
ID: 24891807
why dont you use simple boolean recordprinted (true/false) ?
0
 

Author Comment

by:ture68
ID: 25060474
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
 
LVL 22

Accepted Solution

by:
senad earned 500 total points
ID: 25071107
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
 

Expert Comment

by:rocio car
ID: 41890257
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
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 41890261
That's patience. Waiting 7 years to comment :)
1
 
LVL 22

Expert Comment

by:senad
ID: 41890674
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now