查找控件标题并更改其状态

时间:2016-11-11 09:41:47

标签: delphi controls disabled-control

我有启用/禁用控件的表单,表示表单处于忙或空闲状态。 我需要启用一个控件(一个按钮,但可能是其他),当它被禁用以中止某个进程时。我将按钮标题更改为' ABORT'。

我点击按钮A,我将按钮A的标题改为' ABORT'。所有其他控件都将被禁用,但我想要一个带标题的按钮' ABORT'仍然启用。

var table = d3.select("body").append("table")
                    .attr("style", "margin-left: 50px")
                    .attr("class", "table table-hover table-sm")
                    .attr("id", "tab_id"),
                thead = table.append("thead")
                    .attr("class","tab-head"),
                tbody = table.append("tbody");

                // Append the header row
                thead.append("tr")
                    .selectAll("th")
                    .data(columns)
                    .enter()
                    .append("th")
                    .text(function(column) { return column; });

                // Create a row for each object in the data
                var rows = tbody.selectAll("tr")
                    .data(top_nations)
                    .enter()
                    .append("tr");

                // create a cell in each row for each column
                var cells = rows.selectAll("td")
                    .data(function(row) {
                        return columns.map(function(column) {
                            return {
                                column: column, value: row[column]
                            };
                        });
                    })
                    .enter()
                    .append("td")
                    .attr("style", "font-family: Courier") // sets the font style
                    .html(function(d) { return d.value; });

用法示例:

procedure F1.FormBusy (sender);
var
  a: Integer;
begin
  for a := 0 to TabSheet1.ControlCount - 1 do
  begin
    TabSheet1.Controls[a].Enabled := False;
    (* if TabSheet1.Controls[a] caption := 'ABORT' then
      TabSheet1.Controls[a].Enabled := True
      < how to do this ? *)
  end;
end;

3 个答案:

答案 0 :(得分:5)

不是试图通过其Caption属性找到按钮,为什么不直接从数组中访问它?

for a := 0 to TabSheet1.ControlCount - 1 do
begin
  TabSheet1.Controls[a].Enabled := TabSheet1.Controls[a] = Button1;
end;

除了将启用的Button1之外,每个TControl都将被禁用。

答案 1 :(得分:1)

您可以定义另一种方法来分配繁忙参数:

procedure F1.MAJIHM(const isBusy : Boolean);
var a: Integer;
begin
  for a := 0 to TabSheet1.ControlCount - 1 do
  begin
    TabSheet1.Controls[a].Enabled := isBusy;
  end;
  btnABORT.enabled := not isBusy;
end;

procedure F1.FormBusy (sender);
begin
  MAJIHM(True);
end;

procedure F1.FormIdle (sender);
begin
  MAJIHM(False);
end;

答案 2 :(得分:0)

你说:

  

我单击按钮A,我将按钮A的标题更改为“ABORT”。所有   其他控件将被禁用,但我想要一个带标题的按钮   “ABORT”仍然启用。

从您的使用示例中可以清楚地看到,您将该按钮传递到>>> import ast >>> x = b'test string' >>> y = repr(x) >>> y "b'test string'" >>> ast.literal_eval(y) b'test string' ,您可以在其中将其称为>>> x = 'b\'"Bill of the one\\xe2\\x80\\x99s store wanted to go outside.\'' >>> import ast >>> ast.literal_eval(x) b'"Bill of the one\xe2\x80\x99s store wanted to go outside.' 参数:

F1.FormBusy()

sender功能中,您只需启用所有控件。