有时候我们需要找出某个容器如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;