Solved

Quick Reports Preview Form (Docking)

Posted on 2004-04-08
13
1,428 Views
Last Modified: 2007-12-19
I am writing an application that uses an outlook style menu on the left and all forms are docked on the right hand side using:-

  Form1.show;
  Form1.ManualDock(PnlDock, nil,alNone);

This docks my forms so that they appear on the right hand side of my main form (outlook style view)

My question is, I have written a report using quick reports and when I preview it, up pops the report in its usual preview form.  I cannot seem to manually dock this form as I can with my others.

Help please

Wayne
0
Comment
Question by:coracleit
  • 7
  • 6
13 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10789616
You have to create your custom Preview Form using a TQRPreview...
example'll follow later....
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10789646
OK let's see...

To override the QuickRep preview form you have frst to create a Custom Preview form...
Here is an example by qusoft

{.pas file}

unit prevform;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  qrprntr, ExtCtrls, Menus, Buttons, StdCtrls;

type
  TPreviewForm = class(TForm)
    Panel1: TPanel;
    QRPreview1: TQRPreview;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    Panel2: TPanel;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
  private
    { Private declarations }
    FQRPrinter : TQRPrinter;
  public
    { Public declarations }
    constructor CreatePreview(AOwner : TComponent; aQRPrinter : TQRPrinter);
    property QRPrinter : TQRPrinter read FQRPrinter write FQRPrinter;
  end;

var
  PreviewForm: TPreviewForm;

implementation

{$R *.DFM}

constructor TPreviewForm.CreatePreview(AOwner : TComponent; aQRPrinter : TQRPrinter);
begin
  inherited Create(AOwner);
  QRPrinter := aQRPrinter;
  QRPreview1.QRPrinter := aQRPrinter;
  if (QRPrinter <> nil) and (QRPrinter.Title <> '') then Caption := QRPrinter.Title;
end;

procedure TPreviewForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  QRPrinter.ClosePreview(Self);
  Action := caFree;
end;

procedure TPreviewForm.SpeedButton5Click(Sender: TObject);
begin
  QRPreview1.Zoom := QRPreview1.Zoom + 20;
end;

procedure TPreviewForm.SpeedButton6Click(Sender: TObject);
begin
  QRPreview1.Zoom := QRPreview1.Zoom - 20;
end;

procedure TPreviewForm.SpeedButton2Click(Sender: TObject);
begin
  QRPreview1.PageNumber := QRPreview1.PageNumber - 1;
end;

procedure TPreviewForm.SpeedButton3Click(Sender: TObject);
begin
  QRPreview1.PageNumber := QRPreview1.PageNumber + 1;
end;

procedure TPreviewForm.SpeedButton1Click(Sender: TObject);
begin
  QRPreview1.PageNumber := 1;
end;

procedure TPreviewForm.SpeedButton4Click(Sender: TObject);
begin
  QRPreview1.PageNumber := QRPreview1.QRPrinter.PageCount;
end;

end.

{.dfm file}
 
object PreviewForm: TPreviewForm
  Left = 379
  Top = 253
  Width = 586
  Height = 410
  Caption = 'Report Preview'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  FormStyle = fsMDIChild
  OldCreateOrder = True
  Position = poDefault
  Visible = True
  OnClose = FormClose
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 29
    Height = 363
    Align = alLeft
    BevelOuter = bvNone
    TabOrder = 0
    object SpeedButton1: TSpeedButton
      Left = 2
      Top = 2
      Width = 25
      Height = 25
      Hint = 'First Page'
      Caption = '<<'
      OnClick = SpeedButton1Click
    end
    object SpeedButton2: TSpeedButton
      Left = 2
      Top = 26
      Width = 25
      Height = 25
      Hint = 'Previous Page'
      Caption = '<'
      OnClick = SpeedButton2Click
    end
    object SpeedButton3: TSpeedButton
      Left = 2
      Top = 50
      Width = 25
      Height = 25
      Hint = 'Next Page'
      Caption = '>'
      OnClick = SpeedButton3Click
    end
    object SpeedButton4: TSpeedButton
      Left = 2
      Top = 74
      Width = 25
      Height = 25
      Hint = 'Last Page'
      Caption = '>>'
      OnClick = SpeedButton4Click
    end
    object SpeedButton5: TSpeedButton
      Left = 2
      Top = 98
      Width = 25
      Height = 25
      Hint = 'Zoom in'
      Caption = '+'
      OnClick = SpeedButton5Click
    end
    object SpeedButton6: TSpeedButton
      Left = 2
      Top = 120
      Width = 25
      Height = 25
      Hint = 'Zoom out'
      Caption = '-'
      OnClick = SpeedButton6Click
    end
  end
  object QRPreview1: TQRPreview
    Left = 29
    Top = 0
    Width = 549
    Height = 363
    HorzScrollBar.Tracking = True
    VertScrollBar.Tracking = True
    Align = alClient
    TabOrder = 1
    PageNumber = 1
    Zoom = 100
  end
  object Panel2: TPanel
    Left = 0
    Top = 363
    Width = 578
    Height = 20
    Align = alBottom
    BevelOuter = bvNone
    TabOrder = 2
  end
end

Then you have to Register the New Preview Class in your Application.mainform...

so in your Outlook STyle Form menu declare the type:

TQRSimplePreviewInterface = class(TQRPreviewInterface)
  public
    function Show(AQRPrinter : TQRPrinter) : TWinControl; override;
    function ShowModal(AQRPrinter : TQRPrinter): TWinControl; override;
  end;
in implementation:
function TQRSimplePreviewInterface.Show(AQRPrinter : TQRPrinter) : TWinControl;
begin
  Result := TPreviewForm.CreatePreview(Application, AQRPrinter);
  TPreviewForm(Result).Show;
end;

function TQRSimplePreviewInterface.ShowModal(AQRPrinter : TQRPrinter) : TWinControl;
begin
  Result := TPreviewForm.CreatePreview(Application, AQRPrinter);
  TPreviewForm(Result).ShowModal;
end;

Then Register the PreviewClass in Mainform.OnCreate...

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  // Calling RegisterPreviewClass with the custom
  // interface makes the custom preview the default
  // preview for all reports.
  RegisterPreviewClass(TQRSimplePreviewInterface);
end;


This is just an example but now you can use a preview Docked Form as you need...
0
 

Author Comment

by:coracleit
ID: 10789783

Thanks for the reply, I did this way back in Delphi 1 days, but the way I did it back then no longer works.

I have plugged your example into my project. It compiles, once i realised i needed the qrprntr unit (in case anyone else needs this), but when I run it I get the following error:-

Exception EInvalidOperation in module blah blah
Cannot create form. No MDI forms are currently active.

If I remove the register line in the OnCreate I still get this.

Thanks in advance
Wayne
PS I am not using MDI forms.
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10789791
Sorry, that's beacuse TPreviewForm FOrmSTyle is  FormStyle = fsMDIChild (it come's from a my application)...

Change it to fsNormal....
0
 

Author Comment

by:coracleit
ID: 10790390
Cheers,

Its running now.  if I do myreport.preview the custom preview appears.

Probs, The preview form appears just before the main application appears and where do I put my manualdock code now to get the preview form to appear on the right.

Thanks
Wayne
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10790412
Well, you can add it here
function TQRSimplePreviewInterface.Show(AQRPrinter : TQRPrinter) : TWinControl;
begin
  Result := TPreviewForm.CreatePreview(Application, AQRPrinter);
  TPreviewForm(Result).Show;
  TpreviewForm(result).ManualDock(PnlDock, nil,alNone);
end;

->  The preview form appears just before the main application appears
change the form creation order and availability by project options....

if you want send me you project to

ferruccio (at) afsoftware dot it
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:coracleit
ID: 10790464
Thats where I thought. I had forgotten to put main.pnlDock as its not part of the main form.

Last question I hope.

How do I close it programatically, as I need to close my forms so that the next one can show correctly on the screen.

Close is not an option for a quick report.

Wayne
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10790487
you must create, preview and close your reports exactly like you'd do with the original preview, so simply call
Let's say that you've a TQuickRep called FrmReport:

FrmReport := TFrmReport.create(nil);
FrmReport.Preview; //then simply close the preview form
FrmReport.free; //this frees the preview form
0
 

Author Comment

by:coracleit
ID: 10790597
Although its possible to close the form myself, I need to do it in code.

I can create the report as your code above and it works, but .free will not remove it from the screen and .close is not an option.

Wayne
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10790642
DO you mean that you need to close the report itself? I don't understand exactly this, as i think that if the report is in preview mode, then it'd be possible to print it or close it by some click. BTW you can use the TQuickRep events AfterPrint or AfterPreview calling Close there....
0
 

Author Comment

by:coracleit
ID: 10791090
If you imagine my outlook bar on left.

When the user clicks on a report it appears in the right windows ... fine.

This must stay until the user clicks a new option on the left, ehich could be a setup screen.  The delphi code must close the preview form and show the setup form.

Wayne
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 80 total points
ID: 10791799
OK so
1 - in OutlookBar form add a public property  - PrevForm: TPreviewForm;
2 - in PreviewForm add to the uses the OutlookBar form unit and change this .CreatePreview constructor as follows:

constructor TPreviewForm.CreatePreview(AOwner : TComponent; aQRPrinter : TQRPrinter);
begin
  inherited Create(AOwner);
  OutlookBarForm.PrevForm := self;
  QRPrinter := aQRPrinter;
  QRPreview1.QRPrinter := aQRPrinter;
  if (QRPrinter <> nil) and (QRPrinter.Title <> '') then Caption := QRPrinter.Title;
end;
3 - in the Onclick of the OutlookBar check for the Previewform an destroy it if exists:
procedure CheckPrevForm;
begin
   if PrevForm <> nil then
     Try
        PrevForm.CLose;
     Finally
        FreeAndNil( PrevForm);
     end;
end;

procedure TOutlookBarForm.SomeButtonClick(Sender: TObject);
begin
   CheckPrevForm;
   //do whatever you want;
end;



0
 

Author Comment

by:coracleit
ID: 10792549
Smart....

Thanks for help
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

12 Experts available now in Live!

Get 1:1 Help Now