procedure SetConReadOnly(CurForm: TForm; Value :Boolean); var I: Integer; begin for I := 0 to CurForm.ComponentCount - 1 do begin if CurForm.Components[I] is TDBEdit then TDBEdit(CurForm.Components[I]).ReadOnly := Value; if CurForm.Components[I] is TBitBtn then TBitBtn(CurForm.Components[I]).Enabled := Value; if CurForm.Components[I] is TDBGrid then TDBGrid(CurForm.Components[I]).ReadOnly := Value; if CurForm.Components[I] is TDBGrideh then TDBGrideh(CurForm.Components[I]).ReadOnly := Value; if CurForm.Components[I] is TDBDateTimePicker then TDBDateTimePicker(CurForm.Components[I]).Enabled := not Value; if CurForm.Components[I] is TDBComboBox then TDBComboBox(CurForm.Components[I]).ReadOnly := Value; if CurForm.Components[I] is TDBCheckBox then TDBCheckBox(CurForm.Components[I]).ReadOnly := Value; if CurForm.Components[I] is TDBMemo then TDBMemo(CurForm.Components[I]).ReadOnly := Value; if CurForm.Components[I] is TDBLookupComboBox then TDBLookupComboBox(CurForm.Components[I]).ReadOnly := Value; end; end;//调用 SetConReadOnly(Sender as TForm, True);
在輸入框的onenter 事件裡寫 if (adoquery1.state=dsinsert )or (adoquery1.state=dsedit) then xxx.readonly:=false else xxx.readonly:=true;----- 可以寫成通用的,把其它輸入框的onenter 事件都指向它。 這樣就不用每個輸入框的onenter事件都寫一遍。
var
I: Integer;
begin
for I := 0 to CurForm.ComponentCount - 1 do
begin
if CurForm.Components[I] is TDBEdit then
TDBEdit(CurForm.Components[I]).ReadOnly := Value;
if CurForm.Components[I] is TBitBtn then
TBitBtn(CurForm.Components[I]).Enabled := Value;
if CurForm.Components[I] is TDBGrid then
TDBGrid(CurForm.Components[I]).ReadOnly := Value;
if CurForm.Components[I] is TDBGrideh then
TDBGrideh(CurForm.Components[I]).ReadOnly := Value;
if CurForm.Components[I] is TDBDateTimePicker then
TDBDateTimePicker(CurForm.Components[I]).Enabled := not Value;
if CurForm.Components[I] is TDBComboBox then
TDBComboBox(CurForm.Components[I]).ReadOnly := Value;
if CurForm.Components[I] is TDBCheckBox then
TDBCheckBox(CurForm.Components[I]).ReadOnly := Value;
if CurForm.Components[I] is TDBMemo then
TDBMemo(CurForm.Components[I]).ReadOnly := Value;
if CurForm.Components[I] is TDBLookupComboBox then
TDBLookupComboBox(CurForm.Components[I]).ReadOnly := Value;
end;
end;//调用
SetConReadOnly(Sender as TForm, True);
if (adoquery1.state=dsinsert )or (adoquery1.state=dsedit) then
xxx.readonly:=false
else
xxx.readonly:=true;-----
可以寫成通用的,把其它輸入框的onenter 事件都指向它。
這樣就不用每個輸入框的onenter事件都寫一遍。
在什麽事件下調用?
//调用
SetConReadOnly(Sender as TForm, True);
在post,cancel之后
//调用
SetConReadOnly(Sender as TForm, false);