troubleshooting Question

How to create, at run-time, a copy of a button that was created at design time?

Avatar of krupini
krupini asked on
Delphi
3 Comments1 Solution177 ViewsLast Modified:
Delphi 7.

Say I have a form with one button, all created at design time:

--------------------------------------------------
| Form1                                     _ [ ] [x] |
--------------------------------------------------
|                        [Button 1]                     |
|                                                           |
|                                                           |
|                                                           |
--------------------------------------------------

Now, during run-time, I will need to created additional buttons based on user input. I dont want to creatre a button from scratch, I would much rather create a copy of the existing button, and then change the text and top property ... as everything else will be the same.

I know how to do this:

procedure test;
begin
var
    button2: TButton;
begin
    button2 := TButton.Create(nil); // works ... creates a new button
    // But I want to be able to do something like this or anything that can produce a copy:
    button2 := self.button1.Create(nil);  // assuming button1 was placed on the form at design-time.
end;

Please help. thanks!

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros