清空Form上所有TEdit.Textvar I: Integer; begin for I := 0 to ComponentCount - 1 do if Components[I] is TEdit then TEdit(COmponents[I]).Text := ''; end;
uses TypInfo; var int1:Integer; PropInfo:PPropInfo; begin for int1:=0 to ComponentCount-1 do begin PropInfo:= GetPropInfo( Components[int1], 'text' ); if PropInfo <> nil then SetObjectProp( Components[ int1 ], PropInfo, nil ); end;
楼上的方法有点缺陷!如果出现panel,edit在panel上,上述方法无法清除 建议做个递归procedure TForm1.Button1Click(Sender: TObject); var I:integer; begin For I:=0 to self.ComponentCount-1 do begin if Components[I] is TEdit then TEdit(Components[I]).Text := ''; if Components[I] is TPanel then //或者类似于panel的组件容器 ClearText(Components[I]); end; end;procedure TForm1.ClearText(Cons:TComponent); var I:integer; begin For I:=0 to Cons.ComponentCount-1 do // begin if Components[I] is TEdit then TEdit(Components[I]).Text := ''; if Components[I] is TPanel then //或者类似于panel的组件容器 ClearText(Components[I]); end; end;
to winxkm(蹩脚的程序员) 回答问题时考虑不周或者出错是正常的,我就经常这样,回复一发出再看,啊,错了,哈哈,有时可补充说明挽救,有时没得救,只好认错,我认为这不丢人,而是美德。向我学习,哈哈,我脸都红了,幸亏你看不见。^_^
不是只有TEdit 有text属性,容器也不只TPanel 一个
清除Form上的所有控件的Text可以这样: type TMyControl = class(TControl) public property Text; end;procedure TForm1.Button1Click(Sender: TObject); var I: Integer; begin for I := 0 to ComponentCount - 1 do if Components[I] is TControl then TMyControl(Components[I]).Text := ''; end;
I: Integer;
begin
for I := 0 to ComponentCount - 1 do
if Components[I] is TEdit then
TEdit(COmponents[I]).Text := '';
end;
var
int1:Integer;
PropInfo:PPropInfo;
begin
for int1:=0 to ComponentCount-1 do
begin
PropInfo:= GetPropInfo( Components[int1], 'text' );
if PropInfo <> nil then
SetObjectProp( Components[ int1 ], PropInfo, nil );
end;
建议做个递归procedure TForm1.Button1Click(Sender: TObject);
var
I:integer;
begin
For I:=0 to self.ComponentCount-1 do
begin
if Components[I] is TEdit then
TEdit(Components[I]).Text := '';
if Components[I] is TPanel then //或者类似于panel的组件容器
ClearText(Components[I]);
end;
end;procedure TForm1.ClearText(Cons:TComponent);
var
I:integer;
begin
For I:=0 to Cons.ComponentCount-1 do //
begin
if Components[I] is TEdit then
TEdit(Components[I]).Text := '';
if Components[I] is TPanel then //或者类似于panel的组件容器
ClearText(Components[I]);
end;
end;
clearText(Form)!
回答问题时考虑不周或者出错是正常的,我就经常这样,回复一发出再看,啊,错了,哈哈,有时可补充说明挽救,有时没得救,只好认错,我认为这不丢人,而是美德。向我学习,哈哈,我脸都红了,幸亏你看不见。^_^
type
TMyControl = class(TControl)
public
property Text;
end;procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
for I := 0 to ComponentCount - 1 do
if Components[I] is TControl then
TMyControl(Components[I]).Text := '';
end;