Recent

Author Topic: Cannot assign TObjectDictionary<> to TDictionary<> var  (Read 1060 times)

daniel_sap

  • Full Member
  • ***
  • Posts: 115
Cannot assign TObjectDictionary<> to TDictionary<> var
« on: May 13, 2024, 06:47:56 pm »
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

  • Full Member
  • ***
  • Posts: 171
Re: Cannot assign TObjectDictionary<> to TDictionary<> var
« Reply #1 on: May 13, 2024, 08:36:36 pm »
Hello,

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

 

TinyPortal © 2005-2018