[fpc-pascal] Implementing an interface force me to add _AddRef, _Release

Graeme Geldenhuys graemeg.lists at gmail.com
Fri Apr 16 09:12:04 CEST 2010


Marc Weustink het geskryf:
> 
> or functions like supports() (which uses queryinterface)

Actually, that *does* work with FPC 2.4.0.  See attached console application.

I used supports() and a cast to get a Corba interface reference.
It seems the compiler does some extra magic (probably with the GUID) to
identify the interface via the Supports() call - without the need for
QueryInterface.


begin
 ins := TAddCommand.Create;
 if Supports(ins, ICommand, cmd) then
 begin
   writeln('1. It worked');
   cmd.Execute;               // works
 end;

 cmd := nil;
 cmd := ins as ICommand;
 if Assigned(cmd) then
 begin
   writeln('2. It worked');
   cmd.Execute;                // works
 end;

 ins.Free;
end.

....and the the output generated...

1. It worked
TAddCommand.Execute
2. It worked
TAddCommand.Execute




Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: interface_test.pas
Type: text/x-pascal
Size: 720 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20100416/cdb275a9/attachment.pas>


More information about the fpc-pascal mailing list