如何在delphi中动态创建组件,如TLabel或TEdit等

前端之家收集整理的这篇文章主要介绍了如何在delphi中动态创建组件,如TLabel或TEdit等前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用Delphi 2010
  1. sqlQuery1.First; // move to the first record
  2. while(not sqlQuery1.EOF)do begin
  3. // do something with the current record
  4. // What's the code should i write in this part in order to create a TEdit
  5. // containing the user fullname the current item.
  6. ShowMessage(sqlQuery1['whom']);
  7. sqlQuery1.Next; // move to the next record
  8. end;

解决方法

好吧,要创建一个TEdit,您需要执行以下操作:

创建一个可以使用的变量.局部变量或类成员.

  1. Edit: TEdit;

然后你构建它.

  1. Edit := TEdit.Create(Self);

构造函数的参数是所有者.这可确保在销毁其所有者时销毁该控件.我的假设是自我是一种形式.

现在你需要给控件一个父级.

  1. Edit.Parent := Self;

或者也许是在面板上.

  1. Edit.Parent := StatusPanel;

最后,设置文本.

  1. Edit.Text := sqlQuery1['whom']);

除了使用Caption属性而不是Text属性之外,使用标签它们都非常相似.

你一定会想要设置其他属性,但我想你已经知道如何做到这一点.

猜你在找的Delphi相关文章