PizzaProgram 9 Posted December 4, 2022 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 Bonuš 12 Posted December 4, 2022 For similar reasons, I use an ordinary form with a TfrxPreview component on it. https://www.fast-report.com/documentation/ProgMan/index.html?creating_a_custom_preview_window.htm Share this post Link to post
programmerdelphi2k 237 Posted December 4, 2022 maybe help you: https://www.fast-report.com/public_download/docs/FRVCL/online/en/ProgrammerManual/en-US/Working_with_TfrxReport_component/Creating_a_custom_preview_window.html https://www.fast-report.com/public_download/docs/FRVCL/online/en/ProgrammerManual/en-US/Working_with_TfrxReport_component/Creating_a_report_form_from_code.html Share this post Link to post
PizzaProgram 9 Posted December 4, 2022 (edited) @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 December 4, 2022 by PizzaProgram Share this post Link to post
programmerdelphi2k 237 Posted December 4, 2022 please show your code to create it and say: How would you like to procede? Share this post Link to post
programmerdelphi2k 237 Posted December 4, 2022 (edited) 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. Edited December 4, 2022 by programmerdelphi2k 1 Share this post Link to post
PizzaProgram 9 Posted December 5, 2022 Thank you VERY VERY MUCH ! 🙂 With the help of your example-code, I was able to finish it this way. Share this post Link to post
PizzaProgram 9 Posted December 5, 2022 21 hours ago, programmerdelphi2k said: MyFastPreview.Parent := nil; That was the problem. I've forgot to set that to nil too. Share this post Link to post
PizzaProgram 9 Posted December 5, 2022 (edited) 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 December 5, 2022 by PizzaProgram Share this post Link to post
programmerdelphi2k 237 Posted December 5, 2022 (edited) 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 December 5, 2022 by programmerdelphi2k Share this post Link to post
PizzaProgram 9 Posted December 5, 2022 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
programmerdelphi2k 237 Posted December 5, 2022 (edited) 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 December 5, 2022 by programmerdelphi2k 1 Share this post Link to post