Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array Property, TList, TStringList, or TCollection, etc (Delphi Win32)

I am developing various components, and regularly run into the need to have a property that has a "one-to-many" relationship, component-to-property-member. The components are often visual components, but not always, and sometimes need to be registered with the IDE (i.e. use the Property Inspector), but not always. I find myself unsure of which route to take when setting up these properties -- using an array property, a TList, a TStringList, a TCollection, or something else altogether (perhaps a new class that inherits from one of those).

What are the "best practices" / guidelines for which to use when / where?

like image 316
Jamo Avatar asked Feb 14 '09 05:02

Jamo


People also ask

What is TStringList in Delphi?

TStringList is a utility class type. It is extremely useful for many kinds of list processing. Items in a string list may be inserted, moved and sorted. The list can be built string by string, or loaded from a comma separated big string, or even from a text file.

How many strings can a TStringList hold in c++ builder?

Answer: TStringList can hold up to 134,217,728 strings (MaxListSize+1).


2 Answers

If they are properties, you can descend from TCollection, and then the IDE and Object Inspector will automatically provide support for them via the TCollection Property editor.

like image 79
Nick Hodges Avatar answered Oct 19 '22 02:10

Nick Hodges


TObjectList and TInterfaceList / IInterfaceList are my favorites. And there is TThreadList for thread-safe lists. All of them are available in Delphi 6 (or even before).

like image 37
mjn Avatar answered Oct 19 '22 01:10

mjn