Solved

Clear contents of all controls

Posted on 2002-06-03
3
137 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
[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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

732 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