Board index » delphi » When to use NIL, NULL, UNASSIGNED?

When to use NIL, NULL, UNASSIGNED?

Hello,

These days I find myself having to use third-party COM objects when
undertaking project in Delphi 3.02.  (It seems everyone's API are now
implemented using COM).

I'm a little confused as to how I correctly 'kill' any COM objects that I
create.  For example, if I create a new COM object using:

MyObject:  variant;

MyObject := CreateOleObject('SYNCH.ISYNCH');

Should I kill MyObject by using:
MyObject := nil;

or

MyObject := NULL;

or

MyObject := UNASSIGNED;

or some combination of these?  Under what circumstances should I use each
method?

Any general advice would be appreciated.

----------------------------------------------------
Grant Johnson
grant.john...@acslink.aone.net.au

 

Re:When to use NIL, NULL, UNASSIGNED?


Quote
Grant Johnson wrote in message ...
>I'm a little confused as to how I correctly 'kill' any COM objects that I
>create.

Match the data types.  If MyObject is Variant, then use Null, which is a
Variant.  If MyObject is an interface reference (e.g. IUnknown), use nil.

-- Conrad Herrmann

Re:When to use NIL, NULL, UNASSIGNED?


Actually, it shouldn't really matter which method you use.
The important thing is that, assigning another value to the
variable holding your interface (either IDispatch within a
variant or a specific interface within an interface pointer)
results in your interface getting out of scope. Smart Delphi
here detects that and releases the object. The object
decreases the reference count and will eventually destroy
itself.

--
Pim-Jan Veenendaal
UCC Services
Email: Pim-Jan.Veenend...@ucc.nl

Other Threads