Solved

Quick Reports Preview Form (Docking)

Posted on 2004-04-08
13
1,440 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Virtuailstring tree compare node issue 14 125
Internet Explorer View Settings Question 15 116
code issue 8 154
Create a path if not exists 7 89
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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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