program Project4;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.Classes;
type
IMyInterface =
interface
['
{88DDD9A5-F4BC-47B9-9240-31B1C986F230}']
procedure doSomething();
end;
IMyInterface2 =
interface
['
{D9B8FC6D-2F71-4E31-A5E7-0CCA98146E78}']
procedure doSomeotherthing();
end;
TMyClass =
class(TInterfacedPersistent, IMyInterface, IMyInterface2)
public
procedure doSomething();
procedure doSomeotherthing();
end;
procedure justSupportsThings();
var
myObject: TObject;
myIntf: IMyInterface;
myIntf2: IMyInterface2;
begin
myObject := TMyClass.Create();
try
if Supports(myObject, IMyInterface, myIntf)
then
myIntf.doSomething();
if Supports(myObject, IMyInterface2, myIntf2)
then
myIntf2.doSomeotherthing();
if Supports(myObject, IMyInterface2, myIntf)
then
myIntf.doSomething();
if Supports(myObject, IMyInterface, myIntf2)
then
myIntf2.doSomeotherthing();
finally
myObject.Free;
end;
end;
procedure TMyClass.doSomeotherthing;
begin
Writeln('
Someotherthing');
end;
procedure TMyClass.doSomething;
begin
Writeln('
Something');
end;
begin
try
justSupportsThings();
except
on E:
Exception do
Writeln(E.ClassName, '
: ', E.
Message);
end;
readln;
end.