Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

clear group of edit text

Posted on 2002-03-28
18
Medium Priority
?
260 Views
Last Modified: 2010-04-04
How to fill group of edit.text with zero's(ex: edit1.text,edit2.text........,edit100.text ) with any of loop statments.
thanks
0
Comment
Question by:auokok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
  • +4
18 Comments
 
LVL 2

Expert Comment

by:isstorr
ID: 6902004
 for i := 0 to ComponentCount-1 do
    begin
    if (Components[i].ClassType = TEdit) then
      (Components[i] as TEdit).Text := '0';
    end;
0
 

Author Comment

by:auokok
ID: 6902043
what is the decleration of components
0
 
LVL 2

Accepted Solution

by:
isstorr earned 90 total points
ID: 6902063
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:aubs
ID: 6902305
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
 
LVL 2

Expert Comment

by:isstorr
ID: 6902323
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
 
LVL 2

Expert Comment

by:aubs
ID: 6902358
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
 

Author Comment

by:auokok
ID: 6902359
what is the decleration of components
0
 
LVL 2

Expert Comment

by:isstorr
ID: 6902372
TComponent is in the classes unit
0
 
LVL 2

Expert Comment

by:aubs
ID: 6902377
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
 
LVL 2

Expert Comment

by:isstorr
ID: 6902541
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
 
LVL 2

Expert Comment

by:aubs
ID: 6902619


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
 
LVL 3

Expert Comment

by:VSF
ID: 6903197
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
 
LVL 2

Expert Comment

by:cqhall
ID: 6915391
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
 
LVL 3

Expert Comment

by:D-Master
ID: 6923230
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
 
LVL 2

Expert Comment

by:isstorr
ID: 6924845
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
 
LVL 3

Expert Comment

by:D-Master
ID: 6926680
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
 
LVL 2

Expert Comment

by:isstorr
ID: 6927574
np HTH :)
0
 

Expert Comment

by:SpideyMod
ID: 8280683
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question