Solved

Problem when previewing QuickReport

Posted on 2009-07-01
17
2,695 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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
 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi IDE crash without error message ... 7 99
can't find the executable in Simulator 1 101
Delphi Yen format 3 45
delphi popmenu non latine charcters 3 13
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

821 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