为了实现程序中用户点击的流程控制,
  希望控制在某一容器控件中的Button的Enable顺序
  而这一顺序已经通过TabOrder的数值给出
如,按钮功能为:1新建;2输入;3提交
开始只有 新建 按钮的Enable为True,
按下 新建 后,就只有 输入按钮的Enable为True,
...
按下 提交 后,回环,只有 新建 按钮的Enable为True,这个问题当然可以使用死办法实现,在每个按钮事件中 处理的下一个按钮的属性.我的办法是写一个抽象过程控制:
  遍历容器控件中的所有TButton,
  与要激活的TabOrder比较
  激活指定的TButton现在的问题是:
我采用的遍历手段:AParentCtrl.Controls[WinCtrlIdx]这个属性类型是TControl,
  无法使用(AParentCtrl.Controls[WinCtrlIdx] as TButton)隐射到TButton类型,(编译器报错:类型不匹配)
  使用ABtn:=TButton(AParentCtrl.Controls[WinCtrlIdx])强制隐射,在运行取值ABtn.TabOrder报访问冲突错误.请问各位大侠,此处应该怎么写??附:
procedure FocusNextBtn(CurCtrl : TWinControl);
var
  ParCtrl : TWinControl;
  CurOrd : Integer;
begin
  ParCtrl := CurCtrl.Parent;
  CurOrd := CurCtrl.TabOrder + 1;  CurOrd := FocusBtnByTabOrd(ParCtrl, CurOrd); //-1表示成功  if CurOrd > -1 then FocusBtnByTabOrd(ParCtrl, 0);
end;function FocusBtnByTabOrd(AParCtrl : TWinControl; ATabOrd : Integer) : Integer;
var
  WinCtrlIdx : Integer;
  ChildControl : TControl;
  ABtn : TButton;
begin
  Result := 0;
  for WinCtrlIdx := 0 to AParCtrl.ControlCount - 1 do
  if (AParCtrl.Controls[WinCtrlIdx].ClassName = 'TButton') then
  begin
    ABtn := TButton(AParCtrl.Controls[WinCtrlIdx]); //此处强制转换
    if (ABtn.TabOrder = ATabOrd) then //运行时,错在这里
    begin
      ABtn.Enabled := True;
      Result := -1; 
    end
    else
      ABtn.Enabled := False;
  end; 
end;  

解决方案 »

  1.   

    试试
    if (AParCtrl.Controls[WinCtrlIdx] is TButton) then // 用IS判断
      begin
        ABtn := AParCtrl.Controls[WinCtrlIdx] as TButton; // 用AS转换
        if (ABtn.TabOrder = ATabOrd) then 
        begin
          ABtn.Enabled := True;
          Result := -1; 
        end
        else
          ABtn.Enabled := False;
      end;
      

  2.   

    调用语句FocusNextBtn(Sender as TButton);另:preserve的方法,
      编译器在(AParCtrl.Controls[WinCtrlIdx] is TButton)
      报错"Incompatible types: 'TButton' and 'TControl'"
    谢谢关注.
      

  3.   

    找到原因所在了,因为在Uses中引用了错误的单元
    TButton应该在StdCtrls,因为一时疏忽,写成了QStdCtrls.
    谢谢关注!!