Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

QRCompositeReport i QRPreview

1,953 views
Skip to first unread message

Marcin

unread,
Oct 7, 2003, 5:35:22 AM10/7/03
to
Czy jest jakis sposob aby wywolac podglad kilku polaczonych ze soba raportow
poprzez QRCompositeReport wywolac w QRPreview na wlsnej formie a nie
standardowej formie podgladu wydruku


Jak podpiac poglad wydruku pod QRPreview...???

Z gory dzieki za pomoc

Pozdrawiam

Marcin


Marek Malkowski

unread,
Oct 7, 2003, 8:44:27 AM10/7/03
to
On Tue, 7 Oct 2003 11:35:22 +0200, Marcin <lu...@student.uci.agh.edu.pl>
wrote:

"The way to handle this situation is to use a TQRCompositeReport
component. Drop one on the form where you want to kick off the printing.
First you need to define a handler for its OnAddReports event, which calls
the TQRCompositeReport.Add method to add all the TQuickRep components you
need to print. Suppose the reports you want to print are held on forms
called RepNewCust, RepOrderSummary and RepStockReorder, and in each case
the TQuickRep component on the form is called ‘Report’ (see the section
‘TQuickRep in detail’ below for why you might do this). Then your
OnAddReports event handler should look like this
procedure TForm1.QRCompositeReport1AddReports(
Sender: TObject);
begin
QRCompositeReport1.Reports.Add(RepNewCust.Report);
QRCompositeReport1.Reports.Add(RepOrderSummary.Report);
QRCompositeReport1.Reports.Add(RepStockReorder.Report);
end;

Now you can call QRCompositeReport1.Print to print out all three reports
in a single batch, and QRCompositeReport1.Preview to preview them
together. There are also TQRCompositeReport component properties that let
you set up paper sizes and set an overall title for the composite report –
basically everything you need to handle the output from the multiple
reports in one place.
TQRPreview. To preview a report before it is printed for real, all you
need do is call TQuickRep.Preview and a standard preview window will
appear. There are times, however, when you want to have more control over
the exact appearance of the preview.
The TQRPreview control lets you do this. Drop it on one of your own forms
and, after you have added a line of code to the TQuickRep.OnPreview event,
the control will act as a frame for the previewed report. If you are more
ambitious, or you want to change the preview of a composite report, you
can register your own preview form as the default.
"

i

" Creating a default custom preview

We mentioned back in the ‘Previews and composite reports’ section that it
was possible to change the default preview mechanism. It is time to look
at how this is done."

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

"The first step when creating a custom default preview is to derive a new
class from TQRPreviewInterface, like this:
// use QRPrntr to get TQRPreviewInterface

TQRCustomPreviewInterface = class(TQRPreviewInterface)
public
function Show(AQRPrinter : TQRPrinter)
: TWinControl; override;
function ShowModal(AQRPrinter : TQRPrinter)
: TWinControl; override;
end;

Notice that this is an interface class – it serves only to define a
couple of functions, and has no data of its own. These two functions are
implemented to construct and display your custom preview in non-modal and
modal forms.
Lets suppose that the preview form is going to be called TCustPreview.
Then the implementation of the TQRCustomPreviewInterface methods might
look like this:
function TQRCustomPreviewInterface.Show(
AQRPrinter: TQRPrinter): TWinControl;
var
frm : TCustPreview;
begin
frm := TCustPreview.Create(Application, AQRPrinter);
frm.Show;
Result := frm;
end;

function TQRCustomPreviewInterface.ShowModal(
AQRPrinter: TQRPrinter): TWinControl;
var
frm : TCustPreview;
begin
frm := TCustPreview.Create(Application, AQRPrinter);
frm.ShowModal;
Result := frm;
end;

To register our alternative previewer, we need to call the
RegisterPreviewClass function, which is in the QRPrntr unit. The call
looks like this:
RegisterPreviewClass(TQRCustomPreviewInterface);

Now we are done with the glue code, and can build the actual previewer
form. Mine is minimal; just a single TQRPreview control stuck onto a form:
Figure 17 - Simple preview form

When you do real previews in your applications, you will probably want to
add buttons to call TQRPreview’s Zoom method and other facilities.
To support the previewing mechanism, I had to write a little more code.
Here is the declaration of TCustPreview. Notice I have added a new
constructor, which expects to receive the TQRPrinter argument passed in by
the Show and ShowModal methods of the interface class. Delphi generates a
warning message that the new constructor hides the original. In this case
it is deliberate, so I have wrapped the class in
{$WARNINGS ON} ... {$WARNINGS OFF}
compiler directives to make it shut up.
{$WARNINGS OFF}
TCustPreview = class(TForm)
QRPreview1: TQRPreview;
procedure CustPreviewClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
fQRPrinter : TQRPrinter;
public
{ Public declarations }
constructor Create(AOwner : TComponent;
AQRPrinter : TQRPrinter); virtual;
end;
{$WARNINGS ON}

Finally, here is the implementation of the class. Notice in particular the
cleanup code held in the form’s OnClose event. If you don’t call
ClosePreview here, you will get a nasty memory leak. (QuickReport 2 users
should note that this is a new requirement. You must modify your existing
preview forms when porting them to QuickReport 3 and later.)

constructor TCustPreview.Create(AOwner: TComponent;
AQRPrinter: TQRPrinter);
begin
inherited Create(AOwner);
fQRPrinter := AQRPrinter;
QRPreview1.QRPrinter := AQRPrinter;
end;

procedure TCustPreview.CustPreviewClose(Sender: TObject;
var Action: TCloseAction);
begin
fQRPrinter.ClosePreview(Self);
Action := caFree;
end;
"

--
--
Zaloz prywatne forum:
http://forum.onet.pl

0 new messages