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

大憨熊 提交于 2020-01-11 09:08:24

问题


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?


回答1:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/548567/array-property-tlist-tstringlist-or-tcollection-etc-delphi-win32

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!