Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Globally Clear Multiple Edit Boxes

Status
Not open for further replies.

gforrest

Programmer
Apr 26, 2000
39
0
0
CA
Hi,

I have 28 edit boxes on a form. I want to clear the Text property of all of them (eg. EditBox1.Text :=''). Is there a way to do this globally without having to reference each individual box?

Thanks.
 
for I := 0 to ComponentCount -1 do
if Components is TEdit then
TEdit(Components).Text := '';

 
You can use Form's Components property as bellow:

procedure TForm1.ClearEdit;
var
j: Integer;
nComp : Integer;
begin
nComp := ComponentCount -1;
if nComp >= 0 then
begin
for j := 0 to nComp do
begin
if Components[j] is TEdit then
begin
(Components[j] as TEdit).Text := '';
end;
end;
end;
end;

If there are any TEdit in the Form that you don't want to clear, you can use the Tag property to identify them.

HTH,
Alphonsus.
 
oops... correct my previous post to read


TEdit(Components).Text := '';

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top