Solved

Problem when previewing QuickReport

Posted on 2009-07-01
17
2,592 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

747 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

9 Experts available now in Live!

Get 1:1 Help Now