Why would you need to cast?
If obj supports the interface, and all you need to do is check that before passing it to a procedure, you can simply pass the object itself. The compiler will take care of the rest. You only need the third param on the Supports call if you want to access methods of the interface.
Compile and run the code below. It should compile without errors and present you with a console window and a dialog message.
program Project1;
{$APPTYPE CONSOLE}
uses
Classes
, Dialogs
, SysUtils
;
type
iMyUnknown = interface(IInterface)
['{DA867EBA-8213-4A91-8E03-1AACA150CE77}']
procedure DoSomething;
end;
TMuster = class(TInterfacedObject, iMyUnknown)
procedure DoSomething;
end;
procedure WorkObject(iObj: iMyUnknown);
begin
if Assigned(iObj) then ShowMessage('Got something');
end;
{ TMuster }
procedure TMuster.DoSomething;
begin
beep;
end;
var
obj: TMuster;
begin
try
obj := TMuster.Create;
if Supports(obj, iMyUnknown) then
WorkObject(obj);
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
end.