Board index » delphi » ===>>> Strange behavior when calling _Release

===>>> Strange behavior when calling _Release

OS: NT 4.0 SP 5
Server written with VC++ 6.0 using ATL
Client written in Delphi 3.0 prof.
   -Imported .tlb that was generated by VC++
   -Has a form called SomeForm that contains as a private member,
         m_IStat : IServerStatus; // interface declared in imported .tlb

TSomeForm has two buttons: Connect and Disconnect. Here what goes in
of their event handlers:

in method TSomeForm.OnConnect:
   -CocreateInstance(some_CLSID, nil, CSTCX_ALL, IServerStatus, m_ISat);

   -edit1.Text := m_ISat.Get_ServerName();
in method TSomeForm.OnDisconnect:

loads the local server fine, gets the name of the server and display it
then Delphi fires an exception when it tries to execute m_ISat._Release
in OnDisconnect.

We are supposed to release an interface, are we not?

What gives?


Re:===>>> Strange behavior when calling _Release

Hi Naji,

Nope, you don't call _Release on an interfaces in Delphi unless you are
matching up an _AddRef made on your behalf. Instead you simply set the
interface-pointer to NIL. The compiler will implicitly generate code for
calling _Release.

So the CoCreateInstance-call should be paired with a NIL-assignment.

- Madsen -

Other Threads