简体   繁体   English

Delphi处理大量运行时创建的组件

[英]Delphi Handling a large amount of run time created components

Right now I use 2 arrays one of TImage the other of TMemo to draw an image next to text data row after row inside a scroll box. 现在,我使用2个数组(其中一个是TImage,另一个是TMemo)在滚动框中逐行地在文本数据旁边绘制图像。

I am looking to replace the TMemo with several components on a Panel. 我希望用面板上的几个组件替换TMemo。 So probably some static text a button and some labels. 因此,可能有一些静态文本按钮和一些标签。 But the way I'm doing it now it seems as if this will become messy. 但是我现在的操作方式似乎会变得凌乱。

Is there a better way of going about this without writing a component or class. 有没有一种更好的方法可以解决此问题,而无需编写组件或类。 Should I be using some sort of multi dimensional array or can I use a record structure to declare the components and have an array of that? 我应该使用某种多维数组还是可以使用记录结构来声明组件并拥有一个数组?

A record would at least relieve you of the burden of managing lots of parallel arrays, but you can do better than a record, and better than an array. 一条记录至少可以减轻管理大量并行数组的负担,但是您可以做得比记录更好,也可以比数组做得更好。

First, you can design a frame to represent one "row" of your form. 首先,您可以设计一个框架来代表表单的一个“行”。 Give it an image, button, label, and whatever else you need. 给它一个图像,按钮,标签,以及您需要的其他任何东西。 Then create an instance of that frame class each time you need one. 然后在每次需要时创建该框架类的实例。 It will create the components for you automatically. 它将自动为您创建组件。 You said you didn't want a custom component, and that's essentially what a frame is, but by getting to design it visually like you would a form, much of the burden of creating a composite control is lifted, so you just get the benefit of a group of related controls that can interact with each other as a unit. 您说过您不想要自定义组件,而本质上就是框架,但是通过像在窗体一样直观地设计它,可以减轻创建复合控件的许多负担,因此您可以从中受益可以作为一个单元相互交互的一组相关控件的集合。

Instead of an array, you might find better success with a different collection object, especially TComponentList which can grow and shrink more easily than an array, and also helps manage ownership of its contents. 使用数组对象,而不是数组,可能会获得更好的成功,尤其是TComponentList ,它比数组更容易增长和收缩,并且还有助于管理其内容的所有权。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM