OnPreview event not being called?

hsmhsm
edited 7:33AM in FastReport 4.0
I use Report1.ShowReport(true) to display my report.

In the OnPreview Event of my report I create a toolbar button to allow the user to switch from displaying numbers to displaying percents.

The routine this button calls toggles an enumerated type global variable between Percent and Number which is used to alter how the data is produced and then calls ShowReport(true) again. (The default is to display Percent when first running the report so the button caption offers to change the display to Numbers).

The global variable is also used in the OnPreview event to decide what caption to use for the button (ie 'Display Numbers' or 'Display Percents') and to set which routine to call. See code below...
procedure TFrmOfstedProgressMatrix.frxReportProgressMatrix_KS3Preview(  Sender: TObject);
var
  Button_All,Button_PP,Button_NotPP,Button_SEN, Button_DisplayOption : TSpeedButton;
begin
 
 //... other stuff making  buttons that do other things ---

  //decide what caption and what action to put on the button that switches from dispaying numbers or percents
  if GridDisplayInUse = ShowPercent then //we are showing percents so make the button offer numbers
      begin
      Button_DisplayOption := TSpeedButton.Create(TfrxPreviewForm(frxReportProgressMatrix_KS3.PreviewForm).ToolBar);
      Button_DisplayOption.Parent:=TfrxPreviewForm(frxReportProgressMatrix_KS3.PreviewForm).ToolBar;
      Button_DisplayOption.Caption:='Display Number in Grid';
      Button_DisplayOption.Width:=200;
      Button_DisplayOption.Left:=1650;
      Button_DisplayOption.OnClick:=SetDisplayOptionToNumber; 
      end
  else  //we are showing numbers so make the button offer percents
      begin
      Button_DisplayOption := TSpeedButton.Create(TfrxPreviewForm(frxReportProgressMatrix_KS3.PreviewForm).ToolBar);
      Button_DisplayOption.Parent:=TfrxPreviewForm(frxReportProgressMatrix_KS3.PreviewForm).ToolBar;
      Button_DisplayOption.Caption:='Display Percent in Grid';
      Button_DisplayOption.Width:=200;
      Button_DisplayOption.Left:=1650;
      Button_DisplayOption.OnClick:=SetDisplayOptionToPercent;
      end
end;

The correct default display of Percent is shown, along with the default button caption offering to change it to Number, and clicking the button correctly closes the preview and reopens it showing the new data as numbers (proving the gloabal variable is being changed by my routine)

However, the OnPreview event is never called again so the button caption never changes from its default of Number. Setting breakpoints in the OnPreview event shows it is only ever called once.

Shouldn't the OnPreview event be called each time a report is shown using ShowReport(true)?

If not, is there a way to force it to be called so that the toolbar buttons in one preview can alter what buttons are seen in a subsequent preview of the same report ?


Additional question. Do we need to free the buttons created in the preview event or are they freed when the report is closed?

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.