Jump to content
PizzaProgram

How to handle/close FreeReport's Preview? (D7)

Recommended Posts

I'm trying to create a FastReport Preview that's easier to handle for the user. (Bigger Close button, special page-zoom, etc.)

But I'm a bit confused. Never saw a component that's inherited from TForm but hiding all it's basic functions like: .close();

 

If I try to create it runtime, and place it on my existing form, (inside a panel),

  • how do I CLOSE it from my code ?

Also would like to:

  •  disable the right-click popup
  •   remove the "FastReport - ..." word from the printing title inside the print jobs

 

I've looked at the source code hours long, tried many things, but it ends usually by Access Violation error.

The only thing I was able to find out/fix is:

  • to set MyReport.Preview := nil; after usage, so it does not create error.

 

So how do I close + free a preview (after showed or printed) without destroying the original component, that is paced on the form?

 

Thanks for any help / tip in forward 😉

Share this post


Link to post

@Zoran @programmer

You both misunderstood my question.

I know about the basics.

I know about all those links. Those do not help.

 

I can create reports. (Using them since 20 years.)

 

- But how do I close it safely via code? (For example with a timer.)

ONLY the report-preview, not the whole form it's placed on !

Edited by PizzaProgram

Share this post


Link to post

It would be some like this:

{$R *.dfm}

uses
  frxClass,
  frxPreview;

var
  MyFastReport : TfrxReport;
  MyFastPreview: TfrxPreview;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MyFastReport  := TfrxReport.Create(nil);   // creating on create-form for quick access...
  MyFastPreview := TfrxPreview.Create(nil);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  MyFastPreview.Free;  // destroying on form-destroy!
  MyFastReport.Free;
end;

procedure TForm1.BtnPreparePreviewClick(Sender: TObject);
begin
  if (MyFastReport <> nil) and (MyFastPreview <> nil) then
    begin
      MyFastPreview.Parent := Panel1; // show the "Preview" into "Panel1"
      MyFastPreview.Align  := TAlign.alClient;
      //
      // loading a saved FR file... for quick tests!
      MyFastReport.LoadFromFile('D:\RADRX112Tests\__TEMP\Untitled.fr3');
      //
      // assigning and preparing to show report on Preview...
      MyFastReport.Preview := MyFastPreview; //
      MyFastReport.PrepareReport(true);
    end;
end;

procedure TForm1.BtnClosePreviewClick(Sender: TObject);
begin
  MyFastReport.Preview := nil;  // unAssigning Preview
  MyFastPreview.Parent := nil;
end;

end.

image.thumb.png.552069ab0564cc1193640b62af1b08d5.png

 

Edited by programmerdelphi2k
  • Thanks 1

Share this post


Link to post

I'm still struggling:

How to scroll UP and DOWN a little? (Not a whole page.)

I do not want to add any Focus on that Preview and wanna hide the default scrollbars too.

 

The problem is, that the component is hiding the .FWindow property as it is private. So I can not send any FormKeyDown() event, nor can I reach it's VScrollbar object.

VScrollBar.Position := VScrollBar.Position - VScrollBar.SmallChange // not reachable
MyFastPreview.ScrollBy( 0, -100 ); // does nothing, just flickers the screen for a moment

Any tips how to solve this?

 

Edited by PizzaProgram

Share this post


Link to post
by FastReport DEMO:

  TForm1 = class(TForm)
    frxPreview: TfrxPreview;
    frxReport: TfrxReport;
    HScroll: TScrollBar;
    VScroll: TScrollBar;
    Button1: TButton;
    Button2: TButton;
    procedure HScrollScroll(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
    procedure VScrollScroll(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
    procedure frxPreviewOnScrollPosChange(Sender: TObject; Orientation: TfrxScrollerOrientation; var Value: Integer);
    procedure frxPreviewOnScrollMaxChange(Sender: TObject; Orientation: TfrxScrollerOrientation; Value: Integer);
...

procedure TForm1.HScrollScroll(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
begin
  frxPreview.Workspace.HorzPosition := ScrollPos;
end;

procedure TForm1.VScrollScroll(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
begin
  frxPreview.Workspace.VertPosition := ScrollPos;
end;

procedure TForm1.frxPreviewOnScrollMaxChange(Sender: TObject; Orientation: TfrxScrollerOrientation; Value: Integer);
begin
  if (Orientation = frsVertical) then
    begin
      if (VScroll <> nil) then // not needed under Lazarus
        VScroll.Max := Value;
    end else if (HScroll <> nil) then // not needed under Lazarus
    HScroll.Max := Value;
end;

procedure TForm1.frxPreviewOnScrollPosChange(Sender: TObject; Orientation: TfrxScrollerOrientation; var Value: Integer);
begin
  if (Orientation = frsVertical) then
    begin
      if (VScroll <> nil) then // not needed under Lazarus
        VScroll.Position := Value;
    end else if (HScroll <> nil) then // not needed under Lazarus
    HScroll.Position := Value;
end;


     // assigning and preparing to show report on Preview...
      MyFastPreview.ActiveFrameColor := clBlue;
      MyFastPreview.FrameColor       := clGreen;
      MyFastPreview.BackColor        := clFuchsia;
      MyFastPreview.OutlineColor     := clRed;
      MyFastPreview.OutlineVisible   := true;
      MyFastPreview.HideScrolls      := false;

 

Edited by programmerdelphi2k

Share this post


Link to post
1 minute ago, programmerdelphi2k said:

frxPreview.Workspace

Thanks, but FreeReport does not have that property. 😞

 

I guess I have to change the source code of FreeReport to be able to handle that.

Share this post


Link to post

to access fields/property protected you can try:

 

type

  TMyHack = class(  TClass_to_Hack ) ;;// ex.: TfrxPreview

...

to usage

    TMyHack( instance of object ).xxxxProperty/Field   Ex.: TMyHack( MyPreview )

Edited by programmerdelphi2k
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×