Extending the example program a but further to test for not supported
interfaces I found that the cast (via as syntax) to get a interface gives a
compiler error [test 3 it program]. Using supports() still worked though
[test 4 in program].


Cheers,
  - Graeme -

program interface_test;
{$ifdef FPC}{$mode objfpc}{$h+}{$endif}
{$ifdef mswindows}{$apptype console}{$endif}
{$Interfaces Corba}
uses
 sysutils;
 
type
 ICommand = interface
 ['{28D72102-D883-41A1-9585-D86B24D9C628}']
   procedure   Execute;
 end;
 
 IRunCommand = interface
 ['{C677A645-D7BE-4AC0-986C-FD8B4F86EF26}']
   procedure Run;
 end;


 TAddCommand = class(TObject, ICommand)
 public
   procedure   Execute;
 end;
 
 
procedure TAddCommand.Execute;
begin
  writeln(Classname + '.Execute');
end;



var
 cmd: ICommand;
 ins: TAddCommand;
begin
 ins := TAddCommand.Create;
 if Supports(ins, ICommand, cmd) then
 begin
   writeln('1. It worked');
   cmd.Execute;
 end;
 
 cmd := nil;
 cmd := ins as ICommand;
 if Assigned(cmd) then
 begin
   writeln('2. It worked');
   cmd.Execute;
 end;

{
 cmd := nil;
 cmd := ins as IRunCommand;
 if not Assigned(cmd) then
 begin
   writeln('3. our class does not support IRunCommand interface');
 end;
}

 cmd := nil;
 if not Supports(ins, IRunCommand, cmd) then
 begin
   writeln('4. our class does not support IRunCommand interface');
 end;
   
 ins.Free;
end.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to