如何在不知道组件名称的情况下访问组件的属性? [英] How to access component's properties without knowing its name?

查看:64
本文介绍了如何在不知道组件名称的情况下访问组件的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以使用运行时创建的组件的属性而不知道其名称?意思是说,在您完成此操作之后.

Is there a way to use the properties of a component created in run-time without knowing its name? And by this I mean after you already done this.

with TPanel.Create(self) do
  begin
  Name := 'Panel' + IntToStr(ComponentCount + 1);
  Height := 50;
  Width := 100;
  Top := 30;
  Left := 30;
  Parent := self;
  end;

推荐答案

声明类型为 TPanel 的变量,并将对组件的引用存储在该变量中.

Declare a variable of type TPanel and store a reference to your component in that variable.

var
  Panel: TPanel;
.... 
Panel := TPanel.Create(Self);

然后可以使用此变量引用控件.

You can then refer to the control using this variable.

您可能需要将变量作为表单的成员字段,数组或其他容器保存.

You will likely need to hold the variable as a member field of the form, or in an array, or indeed some other container.

这篇关于如何在不知道组件名称的情况下访问组件的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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