Solved

TLabel.caption set to ''

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

758 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

20 Experts available now in Live!

Get 1:1 Help Now