我想要一个容器里面的所有TDBEdit只读,有什么捷径吗?
一个多 TTabSheet 的界面,
符合某种条件下,
就是希望某一个选中的 TTabSheet 界面里面的容器 Tpanel 里所有的 TDBEdit 或者 TDBComboBox 之类的,只读。有什么快捷的方法吗?很多,如果一个一个写,那是需要很多时间啊。
比如,下面的这一段函数好像不起作用,是为什么呢?
procedure Tform_Pre.SetState(AIndex: Integer; ViewState: Boolean);var i: Integer; tsCur: TTabSheet;begin tsCur := pcSta.Pages[AIndex]; if ViewState then begin for i := 0 to tsCur.ControlCount - 1 do if tsCur.Controls[i] is TDBEdit then begin TDBEdit(tsCur.Controls[i]).ReadOnly := True; TDBEdit(tsCur.Controls[i]).Color := ViewColor; end else if tsCur.Controls[i] is TDBComboBox then begin TDBComboBox(tsCur.Controls[i]).ReadOnly := True; TDBComboBox(tsCur.Controls[i]).Color := ViewColor; end else if tsCur.Controls[i] is TDBDateTimeEditEh then begin TDBDateTimeEditEh(tsCur.Controls[i]).ReadOnly := True; TDBDateTimeEditEh(tsCur.Controls[i]).Color := ViewColor; end else if tsCur.Controls[i] is TDBMemo then begin TDBMemo(tsCur.Controls[i]).ReadOnly := True; TDBMemo(tsCur.Controls[i]).Color := ViewColor; end; end else for i := 0 to tsCur.ControlCount - 1 do if tsCur.Controls[i] is TDBEdit then begin TDBEdit(tsCur.Controls[i]).ReadOnly := False; TDBEdit(tsCur.Controls[i]).Color := clWindow; end else if tsCur.Controls[i] is TDBComboBox then begin TDBComboBox(tsCur.Controls[i]).ReadOnly := False; TDBComboBox(tsCur.Controls[i]).Color := clWindow; end else if tsCur.Controls[i] is TDBDateTimeEditEh then begin TDBDateTimeEditEh(tsCur.Controls[i]).ReadOnly := False; TDBDateTimeEditEh(tsCur.Controls[i]).Color := clWindow; end else if tsCur.Controls[i] is TDBMemo then begin TDBMemo(tsCur.Controls[i]).ReadOnly := False; TDBMemo(tsCur.Controls[i]).Color := clWindow; end; end;end;
end;
end;
Procedure GroupBox_ReadOnly_False(GroupBoxName:TGroupBox);
//引用Windows, System
var
i:integer;
begin
with GroupBoxName do
for i:=0 to controlcount-1 do
begin
if controls[i] is TEdit then TEdit(controls[i]).ReadOnly := False;
if controls[i] is TEdit then TEdit(controls[i]).Color := clwindow;
if controls[i] is TComboBox then TComboBox(controls[i]).Enabled:=True;
if controls[i] is TComboBox then TComboBox(controls[i]).Color:=clwindow;
if controls[i] is TCheckBox then TCheckBox(controls[i]).Enabled:=True;
if controls[i] is TDateTimePicker then TDateTimePicker(controls[i]).Enabled:=True;
if controls[i] is TMemo then TMemo(controls[i]).ReadOnly := False;
if controls[i] is TMemo then TMemo(controls[i]).Color := clwindow;
end;
end;
Procedure GroupBox_Clear(GroupBoxName:TGroupBox);//将GroupBox内项目清空
//引用Windows, System
var
i:integer;
begin
with GroupBoxName do
for i:=0 to controlcount-1 do
begin
if controls[i] is TEdit then TEdit(controls[i]).Clear;
if controls[i] is TComboBox then TComboBox(controls[i]).Text:='';
end;
end;
Procedure GroupBox_Color(GroupBoxName:TGroupBox;StrColor:TColor);
//引用Windows, System
var
i:integer;
begin
with GroupBoxName do
for i:=0 to controlcount-1 do
begin
if controls[i] is TEdit then TEdit(controls[i]).Font.Color := StrColor;
if controls[i] is TComboBox then TComboBox(controls[i]).Font.Color:=StrColor;
if controls[i] is TDateTimePicker then TDateTimePicker(controls[i]).Font.Color:=StrColor;
end;
end;
然后在你的form里调用就可以了
[解决办法]
TDBCombobox(ParentComponent.Controls[i]).Color:=clWindow;
end;
if ParentComponent.Controls[i] is TRZDBEdit then
begin
TRZDBEdit(ParentComponent.Controls[i]).ReadOnly:=bReadOnly;
if bReadOnly then
TRZDBEdit(ParentComponent.Controls[i]).Color:=clBtnFace else
TRZDBEdit(ParentComponent.Controls[i]).Color:=clWindow;
end;
if ParentComponent.Controls[i] is TDBDateTimeEditEh then
begin
TDBDateTimeEditEh(ParentComponent.Controls[i]).ReadOnly:=bReadOnly;
if bReadOnly then
TDBDateTimeEditEh(ParentComponent.Controls[i]).Color:=clBtnFace else
TDBDateTimeEditEh(ParentComponent.Controls[i]).Color:=clWindow;
end;
end;
end;