Been there, done it. I solved a similar problem by deriving a new class from the TListbox class, which included a dynamic array of records that I wanted to bind. You will need to override several TListbox methods to synchronize the dynamic array with the items from the list, but it has several advantages. For example, a dynamic recording array does not need to allocate or de-allocate memory. You just need to set the length of the array to the number of elements in your list. ( SetLength ) You do not access records through pointers, but through an index. You can simply copy entries from one place to another in the list to reorder them.
Disadvantage? This is a lot of functionality that needs to be redefined, and itβs not easy for you to check for errors in your code, since it should work at runtime and development time. Also keep in mind that you are using records, not classes. If you use classes instead, you still need to free every element of the array. But the recordings are much less complicated.
source share