[fpc-pascal] Assigning Interface method to event handler

Michael Van Canneyt michael at freepascal.org
Wed May 25 13:18:49 CEST 2016



On Wed, 25 May 2016, Graeme Geldenhuys wrote:

> Hi,
>
> Can I safely assign a method from an Interface reference to an event
> handler. The code below works, but I'm not sure if it is safe to do so,
> and allowed.
>
> ==================================
>  TTestApp = class(TObject)
>  private
>    rpt: TFPReportReport;
>    FReportFilter: IFPReportFilter; // can hold any export filter
>  ...
>
> constructor TTestApp.Create;
> begin
>  rpt := TFPReportReport.Create(nil);
>  rpt.Author := 'Graeme Geldenhuys';
>  rpt.Title := 'FPReport Demo 4 - Frames and Fonts';
>
>  FReportFilter := TFPReportExportPDF.Create;  // PDF output
>  //FReportFilter := TFPReportExportAggPas.Create;  // PNG output
>  rpt.OnRenderReport := @FReportFilter.RenderReport;
>  ...
> end;

I am not sure this is safe to do, since an event handler exists of 2
pointers: data and method. As far as I know, an interface does not have a
data pointer.

Michael.



More information about the fpc-pascal mailing list