How To…Use ReportModuleVolume Events

Question

“I am registering form based reports with my report server. How can I use ReportModuleVolume event-handlers to control processing on the server?”

Solution

This example defines a TmyReportModuleVolumeController class that manages the ReportModuleVolume.

The ReportModuleVolume is created implicitly by the report catalog when report forms are registered.The ReportModuleVolumeController reads the report volume instance from the catalog and then assigns event-handlers used to control custom processing on the server.

Download: ReportModuleVolumEventHandlers.zip

Sample Delphi code:

type

  TmyReportVolumeController = class
    private
      procedure AttachEventHandlers(aReportVolume: TrsReportVolume);

      procedure ehOnGetDirectory(Sender: TObject; aEventParams: TrsGetDirectoryEventParams);
      procedure ehOnGetReportParameters(Sender: TObject; aEventParams: TrsGetReportParametersEventParams);
      procedure ehAuthenticateReportAccess(Sender: TObject; aEventParams: TrsAuthenticateReportAccessEventParams);

    public
      constructor Create; virtual;

      class function GetVolumeFromCatalog: TrsReportModuleVolume;
      class function VolumeName: String;
      class procedure RegisterReports;
      class procedure Initialize;
      class procedure Finalize;

    end;


implementation


var
  uVolumeController: TmyReportVolumeController;


{******************************************************************************}
{                                                                              }
{  C L A S S   M E T H O D S                                                   }
{                                                                              }
{******************************************************************************}

{TmyReportVolumeController.VolumeName}

class function TmyReportVolumeController.VolumeName: String;
begin
  Result := 'Report Forms';
end;

{TmyReportVolumeController.RegisterReports}

class procedure TmyReportVolumeController.RegisterReports;
begin

  {register the report forms}
  TrsReportCatalog.RegisterReport(VolumeName, 'Customers\Customer List', 'ppReport1', Tfrm001CustomerList);
  TrsReportCatalog.RegisterReport(VolumeName, 'Fish\Biolife', 'ppReport1', Tfrm002Biolife);
  TrsReportCatalog.RegisterReport(VolumeName, 'Customers\Orders\Order List', 'ppReport1', Tfrm003OrderList);
  TrsReportCatalog.RegisterReport(VolumeName, 'Portfolio\Sections', 'ppReport1', Tfrm004Sections);
  TrsReportCatalog.RegisterReport(VolumeName, 'Customers\Orders\Customer Order Item', 'ppReport1', Tfrm005CustomerOrderItem);

end;

{TmyReportVolumeController.Initialize}

class procedure TmyReportVolumeController.Initialize;
begin

  {this method is called from the Intialization section of this unit.}
  RegisterReports;

  uVolumeController := TmyReportVolumeController.Create;

end;

{TmyReportVolumeController.Finalize}

class procedure TmyReportVolumeController.Finalize;
begin

  {this method is called from the Finalization section of this unit.}

  uVolumeController.Free;

end;

{TmyReportVolumeController.GetVolumeFromCatalog}

class function TmyReportVolumeController.GetVolumeFromCatalog: TrsReportModuleVolume;
var
  lVolumeEntry: TrsCatalogVolumeEntry;
begin

  {read the volume entry from the catalog}
  lVolumeEntry := TrsCatalogVolumeEntries.Read(VolumeName);

  {use the volume proxy to access the report volume instance}
  if (lVolumeEntry <> nil) and (lVolumeEntry.Proxy is TrsReportModuleVolumeProxy) then
    Result := TrsReportModuleVolumeProxy(lVolumeEntry.Proxy).Volume
  else
   Result := nil;

end;

{******************************************************************************}
{                                                                              }
{  C O N S T R U C T O R                                                       }
{                                                                              }
{******************************************************************************}

constructor TmyReportVolumeController.Create;
begin

  inherited Create;

  AttachEventHandlers(GetVolumeFromCatalog);

end;

procedure TmyReportVolumeController.AttachEventHandlers(aReportVolume: TrsReportVolume);
begin

  {assign event-handlers}
  aReportVolume.OnGetDirectory := ehOnGetDirectory;
  aReportVolume.OnGetReportParameters := ehOnGetReportParameters;
  aReportVolume.OnAuthenticateReportAccess := ehAuthenticateReportAccess;

end;

{******************************************************************************}
{                                                                              }
{  R E P O R T   V O L U M E   E V E N T   H A N D L E R S                     }
{                                                                              }
{******************************************************************************}

procedure TmyReportVolumeController.ehAuthenticateReportAccess(
  Sender: TObject; aEventParams: TrsAuthenticateReportAccessEventParams);
begin
  messagebeep(0);
end;

procedure TmyReportVolumeController.ehOnGetDirectory(Sender: TObject;
  aEventParams: TrsGetDirectoryEventParams);
begin
  messagebeep(0);

end;

procedure TmyReportVolumeController.ehOnGetReportParameters(
  Sender: TObject; aEventParams: TrsGetReportParametersEventParams);
begin
  messagebeep(0);

end;

{******************************************************************************}
{                                                                              }
{  I N I T I A L I Z A T I O N / F I N A L I Z A T I O N                       }
{                                                                              }
{******************************************************************************}


initialization
  TmyReportVolumeController.Initialize;

finalization
  TmyReportVolumeController.Finalize;