3

我正在使用 Delphi 7。

假设我的表单上有一个页面控件。此页面控件有两个或三个选项卡。每个选项卡上都有一些其他控件,例如标签、编辑等。例如,如何获取代码中编辑的文本属性?

4

2 回答 2

11

Iterate across the controls of the tabsheet using its ControlCount and Controls properties.

for i := 0 to TabSheet.ControlCount-1 do
begin
  if TabSheet.Controls[i] is TEdit then
    ShowMessage(TEdit(TabSheet.Controls[i]).Text);
end;

This will iterate over all immediate children of the tabsheet. If you need to iterate deeper into the children of the children and so on then you want a recursive solution.

If you want to search in each tabsheet then you need to iterate over them too.

for i := 0 to PageControl.PageCount-1 do
  TabSheet := PageControl.Pages[i];
  for j := 0 to TabSheet.ControlCount-1 do
  begin
    if TabSheet.Controls[j] is TEdit then
      ShowMessage(TEdit(TabSheet.Controls[j]).Text);
  end;
于 2013-04-13T19:21:39.590 回答
4

您仍然可以直接访问 TEdit

Edit1.Text := 'My Edit box on a Tab';
于 2013-04-13T20:04:45.453 回答