由于在界面的实现的时候对一些下拉框需要进行禁止输入的限制,但是之前在程序中没有限定,这样在界面中有上百个这样的组件,如果一个个改起来肯定麻烦,可以采用下面的方法进行实现
for i:=ComponentCount-1 downto 0 do begin if Components[i] is TDBComboBox then TDBComboBox(Components[i]).AllowEdit:=False; end;
这样可以达到批量修改组件的属性的功能。
有时候我们的一些组件也需要执行同一个事件的方法,则可以如下处理
procedure TForm.FormShow(Sender: TObject); var i:Integer; begin inherited; for i:=ComponentCount-1 downto 0 do begin if Components[i] is TAYDBDicZLEdit then TDBEdit(Components[i]).OnKeyPress:=DBEditKeyPress; end; DBDicZLEdit2.OnKeyPress:=nil; DBDicZLEdit4.OnKeyPress:=nil; end; procedure TForm.DBEditKeyPress(Sender: TObject; var Key: Char); begin inherited; Key :=#0; end;
这样就实现了事件方法的批量指定。