?
Solved

Problem when previewing QuickReport

Posted on 2009-07-01
17
Medium Priority
?
2,841 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 38

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
 

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 2000 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 38

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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.
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

771 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