Board index » cppbuilder » problems with TLE and smart wrappers used

problems with TLE and smart wrappers used

Hi,
after finishing my first real big COM project I want to comment about two
problems I've run into with Borlands Wizards and the TLE (Type library
editor).

1. Methods using another Interface

Adding an property or method in the TLE with another Interface as parameter
creates an Impl file using smart pointers.
E.g:

STDMETHODIMPL TFoo::Bar( XxxPtr Value)
{
    // only use the other interface,  BUG Release called in ~XxxPtr()
    return S_OK;

Quote
}

Using another interface you don't have to call AddRef/Release. BUT the smart
pointer used by the TLE calls Release on destruction. So it's neccessary to
add a call to AddRef first because Borlands TComInterface wrapper doesn't
call AddRef in the constructor.

STDMETHODIMPL TFoo::Bar( XxxPtr Value)
{
    Value->AddRef();
    // now use the other interface
    return S_OK;

Quote
}

I didn't found any reference to this in the online help nor does C++Builder
4.0 unleashed mentions it.
BORLAND: Why not add the AddRef() call automatically?

2. Property using Variant

Adding a property in the TLE with a Variant creates an get method with call
by value ([IN] Variant) and a set method with call by ref ([OUT] Variant *).
Once again the Impl file uses a smart wrapper, this time it's TVariant. And
once again the problem is the destructor.

STDMETHODIMPL TFoo::set_Bar( TVariant Value)
{
    // problem, on exit ::VariantClear() is called by ~TVariant()
    return S_OK;

Quote
}

On exit the destructor calls ::VariantClear(). BUT this call is done once
again from the client using this property (according to COM rules). In my
case the variant containes a savearray and my VB test application crashed
frequently until i discoverd this problem.

The only solution I found is to change the property in the TLE by hand using
call by ref ([IN] Variant *).

STDMETHODIMPL TFoo::set_Bar( TVariant *Value)
{
    return S_OK;

Quote
}

Conclusion: The auto generated code from the TLE is not always bug free! You
have to carefully look at the details and the source  (utilcls.h).

--
Regards
Martin Rothschink

AxoNet Software GmbH
Osianderstr. 2/1, 73230 Kirchheim unter Teck, Germany
Tel +49 (7021) 735 600, Fax +49 (7021) 735 601
http://www.axonet.de

 

Re:problems with TLE and smart wrappers used


Quote
Martin Rothschink wrote:

[snip]

Quote

> Conclusion: The auto generated code from the TLE is not always bug free! You
> have to carefully look at the details and the source  (utilcls.h).

Martin, please, scream at Borland ( via their bug submission web site )
so they fix it as soon as possible. The more people complain the soone
the fix will appear.
Alex

Other Threads