?
Solved

TLabel.caption set to ''

Posted on 2000-03-23
5
Medium Priority
?
194 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 200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 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