Solved

TLabel.caption set to ''

Posted on 2000-03-23
5
186 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now