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

使用Delphi 2010
SQLQuery1.First; // move to the first record
while(not SQLQuery1.EOF)do begin
   // do something with the current record
   // What's the code should i write in this part in order to create a TEdit
   // containing the user fullname the current item.
   ShowMessage(SQLQuery1['whom']);
   SQLQuery1.Next; // move to the next record
end;

解决方法

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

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

Edit: TEdit;

然后你构建它.

Edit := TEdit.Create(Self);

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

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

Edit.Parent := Self;

或者也许是在面板上.

Edit.Parent := StatusPanel;

最后,设置文本.

Edit.Text := SQLQuery1['whom']);

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

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

相关文章

 从网上看到《Delphi API HOOK完全说明》这篇文章,基本上都...
  从网上看到《Delphi API HOOK完全说明》这篇文章,基本上...
ffmpeg 是一套强大的开源的多媒体库 一般都是用 c/c+&#x...
32位CPU所含有的寄存器有:4个数据寄存器(EAX、EBX、ECX和ED...
1 mov dst, src dst是目的操作数,src是源操作数,指令实现的...