Delphi处理大量运行时创建的组件 [英] Delphi Handling a large amount of run time created components

查看:72
本文介绍了Delphi处理大量运行时创建的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我使用2个数组分别是TImage的TImage和TMemo的另一个,以在滚动框中逐行绘制文本数据旁边的图像。

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.

我正在寻找用面板上的几个组件替换TMemo。所以可能有一些静态文本按钮和一些标签。但是,我现在的操作方式似乎变得一团糟。

I am looking to replace the TMemo with several components on a Panel. 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.

首先,您可以设计一个 frame 来代表表单的一个行。给它一个图像,按钮,标签,以及您需要的其他任何东西。然后在每次需要时创建该框架类的实例。它将自动为您创建组件。您说过您不想要自定义组件,而本质上就是框架,但是通过像在窗体一样直观地设计它,可以减轻创建复合控件的许多负担,因此您可以从中受益

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.

代替一组数组,您可能会发现使用其他集合对象(尤其是<$)会获得更好的成功c $ c> TComponentList 比数组更容易增长和收缩,还有助于管理其内容的所有权。

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.

这篇关于Delphi处理大量运行时创建的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆