请教一个关于Application.Component[]的问题(100分)

T

tl9622

Unregistered / Unconfirmed
GUEST, unregistred user!
我的一个窗体是从另一个窗体继承来的,在这个窗体中,我使用如下的语句,却无效,请问
这是为什么,该如何解决
for i:=0 to ComponentCount-1 do
begin
if Components is TDBEdit then
TDbEdit(Components).ReadOnly:=Yn;
if Components is TDateTimePicker then
TDateTimePicker(Components).Visible:=not Yn;
if Application.Components is TDBLookupComboBox then
TDBLookupComboBox(Components).Enabled:=not Yn;
end;
 
在继承窗体编写
 
我就是在继承的窗体中编写的
 
//用Controls代替Components
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
begin
for i := 0 to ControlCount - 1 do
begin
if Controls is TDBEdit then
TDbEdit(Controls).ReadOnly := Yn;
if Controls is TDateTimePicker then
TDateTimePicker(Controls).Visible := not Yn;
if Application.Controls is TDBLookupComboBox then
TDBLookupComboBox(Controls).Enabled := not Yn;
end;
end;
 
controls应该可以的,我以前用过
 
现在我发现了一个问题,就是我的以上所要求改变属性的控件都是放在GroupBox中的,一旦我去掉
这个groupBox就可以,把控件放进去就不行,请问这应该如何解决?
 
procedure TForm1.Button1Click(Sender: TObject);
var
i, j : Integer;
begin
for i := 0 to ControlCount - 1 do
begin
if Controls is TGroupBox then
begin
for J := 0 to TGroupBox(Controls).ControlCount - 1 do
begin
if Controls[J] is TDBEdit then
TDbEdit(Controls).ReadOnly := Yn;
if Controls[J] is TDateTimePicker then
TDateTimePicker(Controls[J]).Visible := not Yn;
if Application.Controls[J] is TDBLookupComboBox then
TDBLookupComboBox(Controls[J]).Enabled := not Yn;
end;
end;
end;

end;
 
这是我用的代码,作用是清楚查询条件。
procedure TfrmSingleQE.btbClearClick(Sender: TObject);
var i:integer;
aParent:TWinControl;
begin
aParent:=TWinControl(Sender).Parent;
if aParent=nil then Exit;
for i := 0 to aParent.ControlCount-1 do
if aParent.Controls is TEdit then TEdit(aParent.Controls).Clear
else if (aParent.Controls is TComboBox)then
if trim(TComboBox(aParent.Controls).Items[0])='' then
TComboBox(aParent.Controls).ItemIndex:=0
else
TComboBox(aParent.Controls).Text:='';

end;
 
多人接受答案了。
 
顶部