dogI:=TIDog.Create as IDog;
is there any particular reason to cast to IDog?
As TIDog implements IDog, I thought the newly created instance is assignable to a variable of type IDog without any cast.
The compiler, of course, knows that dogI is a COM interface since you have declared it as such. So the compiler does not need the "as" cast at all. However, I included it to make explicit to the reader that at the point of creation your dogI variable refers to an interface.
Because you can also write this:
...
var
dogI: IDog;
dog: TDog;
io: TInterfacedObject;
begin
dog := TDog.Create;
dogI:=TIDog.Create as IDog;
io:=TIDog.Create as TInterfacedObject;
try
dog.Bark;
dogI.Bark;
(io as TIDog).Bark;
finally
dog.Free;
//dogI is automatically freed
io.Free;
end;
WriteLn;
WriteLn('Press Enter to Quit');
ReadLn;
end.