1

I can't use 'TDictionary' as I need a few Values to tag to every Key, instead of 1 value to 1 key.

Example key=1, value1=label1, value2=button3 Example key=2, value1=label5, value2=button7

Will a memory table be best? What is the best TField to use to "record" the Pointer to an object in a TTable?

thanks.

Peter Jones
  • 451
  • 2
  • 12
  • 8
    You can use a `TDictionary`, just use a `record` or `class` as its value type, then add whatever member fields you want – Remy Lebeau Mar 28 '21 at 16:25
  • 2
    To complement what Remy said, you can use a TObjectList as dictionary value type if you need to store a variable number of components. – fpiette Mar 28 '21 at 17:10
  • @RemyLebeau Thanks for the pointer! – Peter Jones Mar 28 '21 at 23:46
  • @fpiette Thanks for the additional info. will explore this! – Peter Jones Mar 28 '21 at 23:46
  • I can think of one situation when a memory table may be more suitable - example need to lookup on more than 1 type of Key. Just for completeness of the answer, can someone answer the question on the TFieldType for memory table to safely store to a pointer for object? I remember reading that integer type is not as safe... – Peter Jones Mar 28 '21 at 23:48
  • 1
    @PeterJones there is no database field type for storing object pointers. However, for an in-memory table that won't be persisted across process boundaries, you can use an integer field, just make sure to use a 32bit or 64bit integer depending on your build target. – Remy Lebeau Mar 28 '21 at 23:59
  • To complement Remy answer, if you use a UIntPtr type, then you can store a pointer regardless of 32 or 64bit platform and regardless of the memory size. UIntPtr is always defined as an unsigned integer having the size of a pointer. – fpiette Mar 29 '21 at 06:29
  • Remy and fpiette, noted with thanks! – Peter Jones Mar 29 '21 at 07:19

0 Answers0