clear group of edit text

How to fill group of edit.text with zero's(ex: edit1.text,edit2.text........,edit100.text ) with any of loop statments.
thanks
auokokAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

isstorrCommented:
 for i := 0 to ComponentCount-1 do
    begin
    if (Components[i].ClassType = TEdit) then
      (Components[i] as TEdit).Text := '0';
    end;
0
auokokAuthor Commented:
what is the decleration of components
0
isstorrCommented:
hi,

ComponentCount and Components are properties of TComponent. The example goes through each component on the form, sees if its a TEdit and if it is, sets its Text property to '0'.

Si
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

aubsCommented:
isstorr is right, but that will change ALL Edit boxes on a form.  You could put your edit boxes in a panel and then call the procedure below.


procedure SetText(Panel: TPanel; Str: String);
var
  i: integer;
  Component: TComponent;
begin
  for i:= Panel.Owner.ComponentCount -1 downto 0 do
  begin
    Component:= Panel.Owner.Components[i];
    if Component is TEdit then
      if (Component as TEdit).Parent= Panel then
         (Component as TEdit).Text:= Str;
     
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetText(panel1, '0');
end;

Aubs
0
isstorrCommented:
As they're properties of TComponent, the technique will work for any container-style component, not just a form.

Aubs - why do you use the Panels Owner? Seems a long-winded way of going about things... Surely you can just use -

procedure SetText(Panel: TPanel; Str: String);
var
 i: integer;
begin
 for i := 0 to Panel.ComponentCount-1 do
   begin
   if (Panel.Components[i].ClassType = TEdit) then
     (Panel.Components[i] as TEdit).Text := Str;
   end;
end;
0
aubsCommented:
Isstorr

Yes you are correct in this instance, but I use something similar to this function to manipulate components on a variety of different forms. (which is where I pulled the bulk of the code from)

I have the procedure stored in a separate unit, and call it from several different forms. I cant remember the exact reason why, but it didn't seem to work properly unless I added the owner bit.

Aubs
0
auokokAuthor Commented:
what is the decleration of components
0
isstorrCommented:
TComponent is in the classes unit
0
aubsCommented:
The 'Components' property lists all components 'owned' by the component.

In certain cases the 'host' component (in this case the panel) may be the parent, but not necessarily the owner of its children.

Aubs



0
isstorrCommented:
Yes I can see how this would work if the edits weren't actually owned by the panel, but in this case we only care about the parent?
0
aubsCommented:


Suppose you have an empty panel (Panel1) and create a button at runtime:

  Button:= TButton.Create(self);  //owner is the form
  Button.Parent:= Panel1;  //parent is the panel
 

Panel.ComponentCount is zero. Looping through Panel1.components would not find the button.

You need to use the Form.Components property.

As I use the SetText function with many forms, the function needs to know which form I mean. (I might have 4 forms each with a panel1).

I could send the form as a parameter: SetText(Form: TForm; Panel: TPanel;...), but as I can get this from the Panel.Owner property, it saves me having to do so.



Here is the function I use to automatically space buttons when a form gets resized. I put it in a unit all on its own.

Drop a panel on a form and set its alignment to alClient.

Drop three buttons on the panel.

In the OnResize event of the panel call the procedure.

procedure ArrangeButtonsHoriz(Panel: TPanel);
var
  i, ButtonCount, ButtonIndex, tmpLeft: integer;
  Component: TComponent;
  Button: TButton;
begin
  ButtonCount:= 0;
  for i:= 0 to Panel.Owner.ComponentCount -1 do
  begin
    Component:= Panel.Owner.Components[i];
    if Component is TButton then
      if (Component as TButton).Parent= Panel then
        inc(ButtonCount);
  end;
  ButtonIndex:= 0;
  for i:= 0 to Panel.Owner.ComponentCount -1 do
  begin
    Component:= Panel.Owner.Components[i];
    if Component is TButton then
      if (Component as TButton).Parent= Panel then
      begin
        Button:= Component as TButton;
        tmpLeft:= Trunc((Panel.Width - (ButtonCount * Button.Width))/ (ButtonCount + 1));
        tmpLeft:= tmpLeft + ButtonIndex * (Button.Width + tmpLeft);
        Button.Left:= tmpLeft;
        inc(ButtonIndex);
      end;
  end;
end;

0
VSFCommented:
Try this!
This procedure enables or disable any component inside a TGroupbox or TPanel, etc...

It can be easely adapted to change any properties of the components inside the group!

//------ Procedure to Enable All Components on a group ------
procedure EnableAll (AWinControl: TWinControl);
var
 i: integer;
begin
 AWinControl.Enabled := TRUE;
 for I := 0 to (AWinControl.ControlCount - 1) do
  begin
   if (AWinControl.Controls [I] is TWinControl) then
    EnableAll (TWinControl (AWinControl.Controls [I]))
   else
    AWinControl.Controls [I].Enabled := TRUE;
  end; {for}
end; {--EnableAll--}


//------ Procedure to Disable All Components on a group ------
procedure DisableAll (AWinControl: TWinControl);
var
 I: integer;
begin
 AWinControl.Enabled := False;
 for I := 0 to (AWinControl.ControlCount - 1) do
  begin
   if (AWinControl.Controls [I] is TWinControl) then
    DisableAll (TWinControl (AWinControl.Controls [I]))
   else
    AWinControl.Controls [I].Enabled := False;
  end; {for}
end; {--DisableAll--}

Hope it helps!

VSF
www.victory.hpg.com.br
www.boatoda.hpg.com.br
0
cqhallCommented:
If you only want to affect the edit boxes that are on a panel (or other container), then use controlcount and controls instead of componentcount and components.  Control lists are based on the parent rather than the owner.

procedure SetText(Panel: TPanel; Str: String);
var
i: integer;
begin
for i := 0 to Panel.ControlCount-1 do
 begin
  if Panel.Controls[i] is tEdit then
     (Panel.Controls[i] as TEdit).Text := Str;
 end;
end;
0
D-MasterCommented:
procedure TForm1.Button1Click(Sender: TObject);
var
  i, ComNum: integer;
begin
  ComNum := 100;
  for i := 1 to ComNum do
    TEdit(FindComponent('Edit'+IntToStr(i))).Text := '0';
end;
0
isstorrCommented:
hi D-Master,

It is customary on EE to always post as comments, to allow the question asker to evaluate all proposed solutions to the problem. See the 'Comments and Answers' tip for more information.

Si
0
D-MasterCommented:
hi all

Thanx isstorr for that tip, but I am new at EE and I didn't notice the difference. I read the 'Comments and Answers'.

Thanx again
0
isstorrCommented:
np HTH :)
0
SpideyModCommented:
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.