for i:=ComponentCount-1 downto 0 do begin if Components[i] is TLabel then TLabel(Components[i]).Visible:=True; end;
for i:=ComponentCount-1 downto 0 do begin if Components[i] is TLabel then (Components[i] as TLabel).Enable:=True; end
你们都是错的,如果是在容器组件,就不能设置了。我的递归清空文本。改下就有了。//=====yeeyee S & T 易一科技===== procedure TFormCYBase.ClearText(AControl:TWinControl); var I: Integer; begin for I := 0 to AControl.ControlCount - 1 do // Iterate begin //需清空处理控件 if AControl.Controls[i] is TCustomEdit then begin (AControl.Controls[i] as TCustomEdit).Text:=''; end; if AControl.Controls[i] is TCustomComboBox then begin (AControl.Controls[i] as TCustomComboBox).ClearSelection; end; //可以 作为 父亲的控件处理事件。 if AControl.Controls[i] is TCustomControl then begin ClearText(AControl.Controls[i] as TCustomControl); end; end; end;procedure TFormCYBase.BitBtn1Click(Sender: TObject); begin ClearText(self); end;
问个问题, Tcustomcontrol为什么是父控件?因为其它自定控件都从它承继?用强制转换会快点 as 操作符比较慢
delphi深度历险 里面有相关的例子
procedure TMainForm.M1Click(Sender: TObject); var i: integer; propinfo:ppropinfo;参考一下 begin //访问form上所有组件 for i:=0 to componentcount-1 do begin propinfo:=getpropinfo(components[i].classinfo,'color'); if propinfo<>nil then setordprop(components[i],propinfo,clblue); end;end;
begin
tedit(findcomponent('edit'+inttostr(i))).visible:=true;
end;
用tedit强制类型转换就可以了。
begin
if Components[i] is TLabel then
TLabel(Components[i]).Visible:=True;
end;
begin
if Components[i] is TLabel then
(Components[i] as TLabel).Enable:=True;
end
procedure TFormCYBase.ClearText(AControl:TWinControl);
var
I: Integer;
begin
for I := 0 to AControl.ControlCount - 1 do // Iterate
begin
//需清空处理控件
if AControl.Controls[i] is TCustomEdit then
begin
(AControl.Controls[i] as TCustomEdit).Text:='';
end;
if AControl.Controls[i] is TCustomComboBox then
begin
(AControl.Controls[i] as TCustomComboBox).ClearSelection;
end;
//可以 作为 父亲的控件处理事件。
if AControl.Controls[i] is TCustomControl then
begin
ClearText(AControl.Controls[i] as TCustomControl);
end;
end;
end;procedure TFormCYBase.BitBtn1Click(Sender: TObject);
begin
ClearText(self);
end;
------------------------------------------------
谁说容器组件内的控件就不能用FindComponent了?只要在form内都可以,加不加self无所谓
tedit(FindComponent('edit1')).Text:='';
这个edit1的parent是一个panel,照样可以
Tcustomcontrol为什么是父控件?因为其它自定控件都从它承继?用强制转换会快点 as 操作符比较慢
var
i: integer;
propinfo:ppropinfo;参考一下
begin
//访问form上所有组件
for i:=0 to componentcount-1 do
begin
propinfo:=getpropinfo(components[i].classinfo,'color');
if propinfo<>nil then
setordprop(components[i],propinfo,clblue);
end;end;