Solved

TLabel.caption set to ''

Posted on 2000-03-23
5
191 Views
Last Modified: 2010-04-04
If I have a form with 10 labels, and I need to set each caption to '' (nothing), how can I do this without writing each one with this Labelx.Caption := ''; Labely.Caption := '';
etc....

I think an Array of some sort, but I'm not sure...

I have this so far:

procedure TForm1.Button2Click(Sender: TObject);
var
i : Integer;
L: String;
begin
i := 1;
 while i < 10 do begin
  inc(i);
  L := 'Label' + IntToStr(i);
  label1.Caption := L;
  end;
end;

Thanks
0
Comment
Question by:routerboy309
[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
5 Comments
 
LVL 3

Accepted Solution

by:
ckaneta earned 50 total points
ID: 2650876
for cnt:= 0 to Form.Componentcount do
 begin
  if (components[cnt] is TLabel) then
   begin
    components[cnt].caption:='';
   end
 end;
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2650880
var
i : Integer;
L: String;
begin
i := 1;
 while i <= 10 do begin
  L := 'Label' + IntToStr(i);
  TLabel(FindComponent(L)).Caption := L;
  inc(i);
  end;
end;
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2650887
To clear the Captions you have to use this of course:

TLabel(FindComponent(L)).Caption := '';
0
 

Expert Comment

by:netbeto
ID: 2650888
Just a correct for the ckaneta's source

var cnt : integer;
begin
for cnt:= 0 to Form1.Componentcount -1 do
 begin
  if (components[cnt] is TLabel) then
   begin
    (components[cnt] as TLabel).caption:='';
   end
 end;

this works fine!!

NetBeto.
0
 

Author Comment

by:routerboy309
ID: 2652917
Thanks - worked (with revision from netbeto) as expected.
0

Featured Post

Independent Software Vendors: 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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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