• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 152
  • Last Modified:

Adding components at runtime

I would like to add Timer at runtime.
The OnTimer event should be able to figure out the name of the Timer.
Example:

for I := 0 to 5 do
begin
  with TTimer.Create(Self) do
  begin
    Interval := 1000;
    Name := 'pp' + IntToStr(I);
    Enabled := True;
    OnTimer := TimerG;
  end;
end;

then the Ontimer event:

procedure TForm1.TimerG(Sender: TObject);
begin
  ShowMessage(self.name);
end;

This will show a message saying 'Form1', but I want it to show 'pp0', 'pp1', 'pp2' ... instead. How?

Greetings.
0
TonyJix
Asked:
TonyJix
2 Solutions
 
ziolkoCommented:
try this:
ShowMessage((Sender as TTimer).Name);

ziolko.
0
 
diniludCommented:
ShowMessage(TTimer(Sender ).Name);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now