Delphi Handling a large amount of run time created components

余生长醉 提交于 2019-12-25 06:22:50

问题


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.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/14554428/delphi-handling-a-large-amount-of-run-time-created-components

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