[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Quick Reports Preview Form (Docking)

Posted on 2004-04-08
13
Medium Priority
?
1,470 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 23

Expert Comment

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

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 23

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 23

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 23

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 23

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 23

Accepted Solution

by:
Ferruccio Accalai earned 320 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

656 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