批量修改容器内所有控件的只读属性

有时候我们需要找出某个容器如Panel,Form里面所有带只读的控件,修改他们的只读属性,如果一个个列出来修改

Edit1.Readonly:=True;

Edit2.Readonly:=True;

Edit3.Readonly:=True;

这样写就太麻烦了,所以我们要批量修改

procedure SetReadOnly(cpn:TComponent;bSetValue:Boolean); 
var i : integer;
begin

  for i := 0 to cpn.ComponentCount  - 1 do
  begin
    if cpn.Components[i].Tag<0 then //这里设置哪些是例外不需要修改,我设置的是Tag小于0
      Continue;

    if GetPropInfo(cpn.Components[i],'ReadOnly')<>nil then   //如果控件有ReadOnly属性
      SetPropValue(cpn.Components[i],'ReadOnly',bSetValue);  //修改ReadOnly 属性

  end;

end;

猜你喜欢

转载自blog.csdn.net/victor_yang/article/details/86984236