Solved

Clear contents of all controls

Posted on 2002-06-03
3
134 Views
Last Modified: 2010-04-04
I need to clear the contents of all my controls tedit, tlabel, etc.  How can I clear the contents of all controls without specifying each control such as Form1.Label1, Form1.Edit1, etc.
0
Comment
Question by:brettawv
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 7051589
for i := 0 to componentcount-1 do
begin
  if components[i] is tlabel then
    tlabel(components[i]).caption := '';
  if components[i] is tedit then
    tedit(components[i]).text := '';
  ...etc
end;

hint
search an ancestor, where the mostly controls are arrived from

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7051592
oops ... brackets missed

if (.. is ..) then
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 7051624
Create a dummy descendaent of TControl to access it's protected Text property and them typecast each control as that dummy class.


For example:

Type
  TMyControl=class(TControl)///dummy class
end;


For loopint:=0 to self.ControlCount-1 do
begin
   TMyControl(Controls[loopint]).text:='';
end;




Good luck!!


0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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