Forum > Packages and Libraries

Cannot assign TObjectDictionary<> to TDictionary<> var

(1/1)

daniel_sap:
Hi,

I have some TDictionary<> and some TObjectDictionary<> fields depending on when the collection needs to own the objects
and trying to assign them to one TDictionary<> field
(unit Generics.Collections)

But got this error
PartForm.pas(135,24) Error: Incompatible types: got "TObjectDictionary<System.AnsiString,System.AnsiString>" expected "TDictionary<System.AnsiString,System.AnsiString>"

Can you, please, help me understand better.
Why just because of the ownership we have so different classes. I was thinking that TObjectDictionary<> will derive from TDictionary<>.

I will cease using TObjectDictionary<> and will manually free the items, but before going in this direction wanted to know what is exactly the situation

Thanks

JdeHaan:
Hello,

The 2nd type parameter must be a class type for a TObjectDictionary.
For 2 string types you should indeed use TDictionary<String, String>

Navigation

[0] Message Index

Go to full version