6

使用德尔福 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;
4

4 回答 4

6

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

创建一个要使用的变量。局部变量或类成员。

Edit: TEdit;

然后你构建它。

Edit := TEdit.Create(Self);

构造函数的参数是所有者。这确保了控件在其所有者被销毁时也被销毁。我的假设是这Self是一种形式。

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

Edit.Parent := Self;

或者它可能在一个面板上。

Edit.Parent := StatusPanel;

最后,设置文本。

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

使用标签,除了使用Caption属性而不是Text属性之外,一切都非常相似。

而且您肯定会想要设置其他属性,但我想您已经知道如何做到这一点。

于 2011-12-16T11:03:13.660 回答
4

您还可以直观地设计组件,使用GExperts 组件对它们进行编码专家,然后再次从表单设计器中删除它们。对于标签/编辑对,这给出了类似

var
  Edit1: TEdit;
  Label1: TLabel;

  Edit1 := TEdit.Create(Self);
  Label1 := TLabel.Create(Self);

  Edit1.Name := 'Edit1';
  Edit1.Parent := Self;
  Edit1.Left := 344;
  Edit1.Top := 172;
  Edit1.Width := 121;
  Edit1.Height := 21;
  Edit1.TabOrder := 0;
  Edit1.Text := 'Edit1';
  Label1.Name := 'Label1';
  Label1.Parent := Self;
  Label1.Left := 296;
  Label1.Top := 176;
  Label1.Width := 65;
  Label1.Height := 17;
  Label1.Caption := 'Label1';
  Label1.FocusControl := Edit1;

大多数时候它需要一些修改(删除 TabOrder 行,用 SetBounds、Align 或您自己的逻辑替换 Left/Top/... 的东西,...)并且对于某些属性/组件它根本不起作用. 但是这样可以节省很多时间。

于 2011-12-16T11:12:47.570 回答
3
Var
  AnEdit : TEdit;
Begin
  AnEdit := TEdit.Create(self);
  AnEdit.Parent := self; // or some suitable container compoent e.g GroupBox, Panel
  AnEdit.Top := ?;
  AnEdit.Left := ?
  // any other properties you weant to set.
End;

吸引人们的一点是设置父母。

于 2011-12-16T11:07:01.833 回答
1
with TEdit.Create(self) do
begin
  Parent:= ... // The name of the panel or form, on which you would like to place TEdit
  Text:= 'your text'; 
  // And you could set its position by giving "Left" and/or "Width", so on..
end;
于 2018-06-26T11:00:06.363 回答