Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2019-04

Using TInterfaceList and casting interfaces

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Benito van der Zander

Hi,

how should one use TInterfaceList with other interfaces than IUnknown? Let's say we have a ISomeInterface derived from IUnknown.

When we have an ISomeInterface, we can add it to the list fine, because an ISomeInterface is an IUnknown.

But when we get it back from the list, it is an IUnknown and not an ISomeInterface.

Writing (list.get(0) as ISomeInterface), is very slow and not possible, when the interface has no GUID.

Writing ISomeInterface(list.get(0)) usually works fine, but when -CR is set, it does not compile.

Writing ISomeInterface(pointer(list.get(0))) appears to work, but is that safe, or does it confuse the reference counting?

Or perhaps it is better to use gvector rather than TInterfaceList?

Best,

Benito

Reply by email

Sven Barth
to Benito van der Zander

Benito van der Zander schrieb am So., 7. Apr. 2019, 15:34:

Writing (list.get(0) as ISomeInterface), is very slow and not possible, when the interface has no GUID.

This is indeed what is supposed to be used with TInterfaceList.

Or perhaps it is better to use gvector rather than TInterfaceList?

If you only store a specific interface type then using one of the generic containers specialized to that type would indeed be best.

Regards,
Sven

Reply by email

Benito van der Zander
to Sven Barth

Hi,

Show quoted text 7 lines
Or perhaps it is better to use gvector rather than TInterfaceList? If you only store a specific interface type then using one of the generic containers specialized to that type would indeed be best.

 and on a closer look TInterfaceList does a lot of locking.

guess TInterfaceList should be avoided, unless you actually need something thread-safe. The classes unit is full of weird stuff

Best,
Benito

Sven Barth wrote 22 lines
Benito van der Zander < > schrieb am So., 7. Apr. 2019, 15:34: Writing (list.get(0) as ISomeInterface), is very slow and not possible, when the interface has no GUID. This is indeed what is supposed to be used with TInterfaceList. Or perhaps it is better to use gvector rather than TInterfaceList? If you only store a specific interface type then using one of the generic containers specialized to that type would indeed be best. Regards, Sven _______________________________________________ fpc-pascal maillist http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email