数组属性、TList、TStringList 或 TCollection 等 (Delphi Win32)

发布于 2024-07-13 20:00:28 字数 223 浏览 4 评论 0原文

我正在开发各种组件,并且经常遇到需要拥有一个具有“一对多”关系(组件到属性成员)的属性。 这些组件通常是可视组件,但并非总是如此,有时需要向 IDE 注册(即使用属性检查器),但并非总是如此。 我发现自己不确定在设置这些属性时要采取哪条路线——使用数组属性、TList、TStringList、TCollection 或其他东西(可能是从其中一个继承的新类)。

何时/何地使用的“最佳实践”/指南是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

洛阳烟雨空心柳 2024-07-20 20:00:29

如果它们是属性,您可以从 TCollection 继承,然后 IDE 和对象检查器将通过 TCollection 属性编辑器自动为它们提供支持。

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.

音栖息无 2024-07-20 20:00:29

TObjectList 和 TInterfaceList / IInterfaceList 是我的最爱。 还有用于线程安全列表的 TThreadList。 所有这些都可以在 Delphi 6(甚至更早版本)中使用。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文