I'm an experienced programmer, but I'm working on my first Delphi project, and I've run into what seems to be a simple misunderstanding on my part.
Here is a snippet of the code. I am unable to insert Objects implementing the ITimeListener interface into a TObjectList. Retrieving the objects is ugly, and so I guess I am doing something wrong.
Do I just misunderstand what interfaces are in Delphi?
TExternalTimer = class(TInterfacedObject, ITimeListener)
procedure OnCorrectedTimeEvent(Bib: String; Channel: Integer; Time: TRaceTime);
procedure RegisterListener(Listener: ITimeListener);
procedure TExternalTimer.OnCorrectedTimeEvent(Bib: String; Channel: Integer; Time: TRaceTime);
for I := 0 to (mListeners.Count - 1) do
((mListeners[I] as TInterfacedObject) as ITimeListener)
.OnCorrectedTimeEvent(Bib, Channel, Time);
procedure TExternalTimer.RegisterListener(Listener: ITimeListener);
// This complains that I TObject and ITimeListener are incompatible.
From what I've seen, Delphi doesn't seem to treat interfaces as a "view" into some concrete object. They are a different beast altogether and that, I think, is what's making my head hurt.