同时有有什么办法能同时让DBEdit能被编辑。

解决方案 »

  1.   

    for i := 0 to self.ComponentCount - 1 do begin
          if (self.Components[i] is TDBEdit) then
            TDBEdit(Self.Components[i]).ReadOnly := True;
        end;Self也可以换成你的DBEdit所在的Panel
      

  2.   

    呵, 用递归class procedure TDBFunction.SetDBControlReadOnly(aParentControl: TWinControl; aValue: Boolean);
    var
      i: integer;
      p: PPropInfo;
    begin
      for i := 0 to aParentControl.ControlCount - 1 do
      begin
        if not (aParentControl.Controls[i] is TWinControl) then Continue;    if csAcceptsControls in aParentControl.Controls[i].ControlStyle then
          SetDBControlReadOnly(TWinControl(aParentControl.Controls[i]), aValue);    if aParentControl.Controls[i] is TPageControl then
          SetDBControlReadOnly(TWinControl(aParentControl.Controls[i]), aValue);    p := GetPropInfo(aParentControl.Controls[i].ClassInfo, 'ReadOnly');
        if Assigned(p) then
          SetPropValue(aParentControl.Controls[i], 'ReadOnly', aValue);
      end;
    end;
      

  3.   

    你将要控制的TDBEdit控件取类似的名字:
    例如:DBEdtIn1,DBEdtIn2....DBEdtIn50然后:
    var
    CanEdit:Booean;
    begin
      for I:=1 to 50 do
      begin
        TDBEdit(FindComponent('DBEdtIn'+IntTostr(I))).ReadOnly:=not CanEdit;
        if CanEdit then  //还可以控制颜色
          TDBEdit(FindComponent('DBEdtIn'+IntTostr(I))).Color:=clWindow
        else
          TDBEdit(FindComponent('DBEdtIn'+IntTostr(I))).Color:=clInfoBk;
      end;
    end;
      

  4.   

    你直接用Query.Readonly := true;即可控制所有字段都不能编辑。
      

  5.   

    如果是DBedit的话,最好直接对数据源的进行控制,让数据源来控制数据感知控件。
      

  6.   

    父控件.enabled := false; 不要说编辑,焦点都不让你得到。:)
      

  7.   

    ssq237712(流亡帅哥) 与我想的一样.