View Issue Details

IDProjectCategoryView StatusLast Update
0037794LazarusLazReportpublic2020-09-30 11:25
ReporterZdravko Gabrovski Assigned ToJesus Reyes  
Status closedResolutionfixed 
Product Version2.1 (SVN) 
Fixed in Version2.1 (SVN) 
Summary0037794: New "Onbeforepreview" event in LazReport
DescriptionIn the current version of LazReport, the developer has no control over the standard "Preview report" form.
In my case I am developing a plugin dll library, which uses lazrRepor in DLL as a non-modal form. I need to set form style of the standard preview form to "fsStayOnTop" and register the form in object list, that I will use later on to free the form objects (as it is known, it is not possible to set action=caFree in non modal form in dll, it raises AV).

To solve all the cases, I just add a new event handler called "OnBeforePreview" in LazReport. It will pass by reference already created preview form, which will give an option to developer to modify it.

New Event Hadler type:

TBeforePreviewFormEvent = procedure( var PrForm : TfrPreviewForm ) of Object;

Nee variable:
fOnBeforePreview : TBeforePreviewFormEvent;

And new property:
property OnBeforePreview : TBeforePreviewFormEvent read fOnBeforePreview write fOnBeforePreview;

And small modification in procedure TfrReport.ShowPreparedReport:

    if Assigned( OnBeforePreview ) then
      OnBeforePreview( p );

and a sample of usage in my code:

procedure TDataModule2.frReport1BeforePreview(var PrForm: TfrPreviewForm);
PrForm.FormStyle := fsStayOnTop; // Changle preview form style; In DLL if it if fsNormal, the user can hide the form
PrForm.OnClose := @FormCloseHandler; // I am using this to add a form object to object list for free the non-modal forms created in dll

Steps To ReproduceEnhancement
TagsNo tags attached.
Fixed in Revision63938
Attached Files


Zdravko Gabrovski

2020-09-22 09:59


lr_class.diff (1,683 bytes)   
Index: components/lazreport/source/lr_class.pas
--- components/lazreport/source/lr_class.pas	(revision 63906)
+++ components/lazreport/source/lr_class.pas	(working copy)
@@ -140,6 +140,7 @@
   TPrintReportEvent = procedure(Sender: TfrReport) of object;
   TFormPageBookmarksEvent = procedure(Sender: TfrReport; Backup: boolean) of object;
   TExecScriptEvent = procedure(frObject:TfrObject; AScript:TfrScriptStrings) of object;
+  TBeforePreviewFormEvent = procedure( var PrForm : TfrPreviewForm ) of Object;
   TfrHighlightAttr = packed record
     FontStyle: Word;
@@ -1148,6 +1149,7 @@
     FObjectClick: TObjectClickEvent;
     FOnExportFilterSetup: TExportFilterSetup;
     fOnFormPageBookmarks: TFormPageBookmarksEvent;
+    fOnBeforePreview : TBeforePreviewFormEvent;
     FPages: TfrPages;
     FEMFPages: TfrEMFPages;
     FRebuildPrinter: boolean;
@@ -1364,6 +1366,7 @@
     property OnObjectClick: TObjectClickEvent read FObjectClick write FObjectClick;
     property OnMouseOverObject: TMouseOverObjectEvent read FMouseOverObject write FMouseOverObject;
     property OnFormPageBookmarks: TFormPageBookmarksEvent read fOnFormPageBookmarks write fOnFormPageBookmarks;
+    property OnBeforePreview : TBeforePreviewFormEvent read  fOnBeforePreview write fOnBeforePreview;
   TfrCompositeReport = class(TfrReport)
@@ -11509,6 +11512,8 @@
       p.SaveDialog.InitialDir := ExtractFilePath(ExportFileName);
       p.SaveDialog.FileName := ExportFilename;
+    if Assigned( OnBeforePreview ) then
+      OnBeforePreview( p );
   {$IFDEF DebugLR}
lr_class.diff (1,683 bytes)   

Jesus Reyes

2020-09-24 09:43

developer   ~0125806

Shouldn't this be triggered also in case of custom preview form?

Zdravko Gabrovski

2020-09-24 11:18

reporter   ~0125811

I think no - in a custom preview form the developer has full control over it.
the problem in my case is with standard preview form.

Jesus Reyes

2020-09-29 07:37

developer   ~0125951

Thanks, Applied.

Zdravko Gabrovski

2020-09-30 11:25

reporter   ~0125981


Issue History

Date Modified Username Field Change
2020-09-22 09:59 Zdravko Gabrovski New Issue
2020-09-22 09:59 Zdravko Gabrovski File Added: lr_class.diff
2020-09-24 09:12 Jesus Reyes Assigned To => Jesus Reyes
2020-09-24 09:12 Jesus Reyes Status new => assigned
2020-09-24 09:43 Jesus Reyes Status assigned => feedback
2020-09-24 09:43 Jesus Reyes LazTarget => -
2020-09-24 09:43 Jesus Reyes Note Added: 0125806
2020-09-24 11:18 Zdravko Gabrovski Note Added: 0125811
2020-09-24 11:18 Zdravko Gabrovski Status feedback => assigned
2020-09-29 07:37 Jesus Reyes Status assigned => resolved
2020-09-29 07:37 Jesus Reyes Resolution open => fixed
2020-09-29 07:37 Jesus Reyes Fixed in Version => 2.1 (SVN)
2020-09-29 07:37 Jesus Reyes Fixed in Revision => 63938
2020-09-29 07:37 Jesus Reyes LazTarget - => 2.2
2020-09-29 07:37 Jesus Reyes Note Added: 0125951
2020-09-30 11:25 Zdravko Gabrovski Status resolved => closed
2020-09-30 11:25 Zdravko Gabrovski Note Added: 0125981