Solved

Show a label on a form created at runtime

Posted on 1998-06-18
2
169 Views
Last Modified: 2010-04-04
At runtime a have created a form. How can I create a label on this form at runtime so a can display a message.

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

Accepted Solution

by:
Pegasus100397 earned 200 total points
ID: 1353863
lpd,

 Put a label on the form, set it's caption to blank (nothing) so it does not show any text. At runtime simply assign a value to the Caption of the Label with something like:

Label1.Caption := 'Hi There!';

Good luck with your project!
Pegasus
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1353864
Okay...you can also create your label at runtime...



type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Label1 : TLabel;
    procedure MyClick(Sender: TObject);
  end;

var
  Form1: TForm1;


implementation

{$R *.DFM}

procedure TForm1.MyClick(Sender: TObject);
begin
  ShowMessage('Hello');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Label1 := TLabel.create(self);
with Label1 do
begin
  parent := self;  //or the form/panel...
  top := 10;
  left := 20;
  caption := 'My Message';
  onclick := myClick;
  show;
end;
end;

end.

Rick

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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