我的意思是现在有10个按钮visible均为false,caption均为空,根据qxb中的数据来定义这些按钮的visible属性和caption,qxb中的数据如下
role     an       caption           form
总经理 Button1 接单查询          jdcx
总经理 Button2 出口发货查询 fhcx
总经理 Button3 内销发货统计 nxtjcx
总经理 Button4 客户数据分析 khsjfx
以上各字段均为string类型
procedure TForm1.Button2Click(Sender: TObject);
var
  btn: TButton;
begin
  qya.close;
  qya.sql.clear;
  qya.sql.add('select * from qxb where role=''总经理''');
  qya.open;
  while not qya.Eof do
  begin
  btn:=qya.fieldbyname('an').asstring;
  btn.Visible := True;
  qya.Next;
  end;
end;
以上代码编译时提示‘incompatible:'TButton' and 'String'’;
请问该符合写代码?

解决方案 »

  1.   

    btn.caption:=qya.fieldbyname('an').asstring;
      

  2.   

    实现你所需功能,可以参照下面的代码:
    procedure TForm1.Button4Click(Sender: TObject);
    var
      btnName :string;
      i :integer;
    begin
      btnName := 'Button1';
      for i := 0 to ComponentCount-1 do
        if Components[i] is TButton then
        begin
          if TButton(Components[i]).Name = btnName then
          begin
            TButton(Components[i]).Caption := '接單查詢';
            TButton(Components[i]).Visible := True;
          end;
        end;
    end;
      

  3.   

    你可以参考一下这里:http://topic.csdn.net/u/20101016/12/78bc299d-d5e8-4808-b7f7-2397eba72f7a.html
      

  4.   

    为哪个赋值,那是你决定的,如果你知道按钮的名字,就按照2楼的方法,写一个查找button的方法,然后为找到的button赋值
      

  5.   

    你这10个button是有规则的,还是可以随便用的,如果是的话就可以定义一个数组把10个button保存下来,再处理,你这个需求有点奇怪哦,有还要不要响应button的事件啊,可以参考如下:var
      i: Integer;
      btnArr: array [1..10] of TButton;
    begin
      for i := 0 to ControlCount - 1 do
      begin
        if Controls[i] is TButton then
          btnArr[i+1] := TButton(Controls[i]);
      end;
      qya.close;
      qya.sql.clear;
      qya.sql.add('select * from qxb where role=''总经理''');
      qya.open;
      i := 1;
      while not qya.Eof do
      begin
        btnArr[i].Caption := qya.fieldbyname('an').asstring;
        btnArr[i].Visible := True;
        inc(i);
        if (i>10) then Break;
        qya.Next;
      end;
    end;
      

  6.   

    放10個按鈕在Form上,命名為Btn1,Btn2...Btn10,設置visible=falseprocedure TForm1.Button2Click(Sender: TObject);
    var
      i:integer;
    begin
      for i:=1 to 10 do
        TButton(Self.FindComponent('Btn'+(intTostr(i)))).Visible := False;
      with qya do
      begin
        close;
        sql.text:='select * from qxb where role=''总经理''';
        open;
        i:=1;
        while not Eof do
        begin
          with TButton(Self.FindComponent('Btn'+(intTostr(i)))) do
          begin
            caption:=fieldbyname('an').asstring;
            Visible := True;
          end;
          Next;
          inc(i);
        end;
      end;
    end;
      

  7.   

    支持
    var
      i: Integer;
      btnArr: array [1..10] of TButton;
    begin
      for i := 0 to ControlCount - 1 do
      begin
        if Controls[i] is TButton then
          btnArr[i+1] := TButton(Controls[i]);
      end;
      qya.close;
      qya.sql.clear;
      qya.sql.add('select * from qxb where role=''总经理''');
      qya.open;
      i := 1;
      while not qya.Eof do
      begin
        btnArr[i].Caption := qya.fieldbyname('an').asstring;
        btnArr[i].Visible := True;
        inc(i);
        if (i>10) then Break;
        qya.Next;
      end;
    end;
      

  8.   

    支持
    var
      i: Integer;
      btnArr: array [1..10] of TButton;
    begin
      for i := 0 to ControlCount - 1 do
      begin
        if Controls[i] is TButton then
          btnArr[i+1] := TButton(Controls[i]);
      end;
      qya.close;
      qya.sql.clear;
      qya.sql.add('select * from qxb where role=''总经理''');
      qya.open;
      i := 1;
      while not qya.Eof do
      begin
        btnArr[i].Caption := qya.fieldbyname('an').asstring;
        btnArr[i].Visible := True;
        inc(i);
        if (i>10) then Break;
        qya.Next;
      end;
    end;
      

  9.   

    btn.caption:=qya.fieldbyname('an').asstring;
      

  10.   

    搞这么复杂,
    用Action 是楼主权限没有定义好
      

  11.   

    btn.caption:=qya.fieldbyname('an').asstring