Eventsink Interface implementing as interface variable?

Hi there,

Simple question. Using Delphi, code first. Instead implementing the event interface like this:

  TFormMain = class(TForm, IEvents)
 

i would like to have the interface as variable:

 TFormMain = class(TForm)
 private
   FEventInterface: IEvents;
 end

procedure TFormMain.FormCreate(Sender: TObject);
begin
 // FEventInterface:= how to do this?
end;

Is this possible?
The reason is i have to write a huge testcase with a local IEvents implementation. And this should be possible switching by configuration. I did it already with the service interfaces. But i’m stuck here with the event interface.

Hi,

We have use this in our testcases:

  TestEventObject = class(TComponent, ITest_EventSink)
  public
    procedure Event_String(const NewParam: ROAnsiString);
    procedure Event_Struct(const NewParam: TestStruct);
  end;

//var levent: TestEventObject;
      levent := TestEventObject.Create(nil);
      ev.RegisterEventHandler(EID_Test_EventSink, levent);
      ev.Activate;

Yes. I did it like this already. But i’ve missed the RegisterEventHandler stuff.
Thanks for that.