Section 7.6 in the FreePascal Language Reference discusses automatic reference counting for COM interfaces. It details assignments to variables and temporary variables. But the section doesn't mention parameter passing. What happens when interfaces are passed to functions, procedures and methods ?

From reading Delphi documentation and by experimenting a bit, there seems to be a great difference between value and CONST parameters and between VAR and OUT parameters. I suggest to extend the manual to explain this in detail.

For example, I have an interface IMFMediaEventGenerator (from Windows MediaFoundation) with a method GetEvent

  type
    IMFMediaEventGenerator = interface( IUnknown) ...
        ....
         function GetEvent( dwFlags: DWORD; out ppEvent: IMFMediaEvent): 
HResult; stdcall;

Now, suppose I am calling GetEvent in a loop

      theEvent := nil;
      theEventType := MEUnknown;
      theResult := S_OK;
      while ( theEventType <> MESessionClosed) and ( theResult >= S_OK) do
      begin
        theResult := theSession.GetEvent( 0, theEvent);
        ...

Now, it seems (correct me if I am wrong) that theEvent doesn't need to be manually released, because it has been declared as an OUT parameter rather than a VAR parameter. So, if this is true, this information is crucial when writing interface bindings.

In general, I am not a proponent of "compiler magic" because it confuses things, puts it under the table. I would certainly welcome a compiler option to NOT auto-refcount.

Regards,

Adriaan van Os

_______________________________________________
fpc-devel maillist  -  [email protected]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to