Why do I need to implement TInterfacedObject when implementing my own interfaces? Example:
I created the following interface:
unit updatable;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type
IUpdatable = interface
procedure Update;
end;
implementation
end.
Then I created the following class:
unit gameobject;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, updatable;
type
{ TGameObject }
TGameObject = class(TInterfacedObject, IUpdatable)
procedure Update;
procedure Draw;
end;
implementation
{ TGameObject }
procedure TGameObject.Update;
begin
end;
procedure TGameObject.Draw;
begin
end;
end.
Why if I remove the TInterfacedObject from the declaration of TGameObject I get the following errors?
Compile Project, Target: TestGame.exe: Exit code 1, Errors: 6
gameobject.pas(14,17) Error: No matching implementation for interface method "IUnknown.QueryInterface(constref TGuid,out <Formal type>):LongInt; StdCall;" found
gameobject.pas(14,17) Error: No matching implementation for interface method "IUnknown._AddRef:LongInt; StdCall;" found
gameobject.pas(14,17) Error: No matching implementation for interface method "IUnknown._Release:LongInt; StdCall;" found
gameobject.pas(14,17) Error: No matching implementation for interface method "IUnknown.QueryInterface(constref TGuid,out <Formal type>):LongInt; StdCall;" found
gameobject.pas(14,17) Error: No matching implementation for interface method "IUnknown._AddRef:LongInt; StdCall;" found
gameobject.pas(14,17) Error: No matching implementation for interface method "IUnknown._Release:LongInt; StdCall;" found
Thanks!