1
votes

Delphi-version5. I have a file comparison app I am putting together and it has a Left and Right Panel on the main form. Each panel (pnlLeft and pnlRight) has an identical range of Controls and events only separated by name. i.e btnCheckLeft(... and btnCheckRight(... and I am having problems keeping the code changes synched between the two Panels.

I am wondering if I can make a single Panel (on a separate Form) with all of the controls and events and then at runtime, copy it twice, once for the pnlLeft an the other, the pnlRight to the main form. On that single Form, I can manage the coding just the once instead of trying to duplicate everything.

During the process, set the Align and the Event names to apply to each copy as in...

The first copy to the blank main form...

pnlLeft.Align:=alLeft;
pnlLeft.Button1Click(Sender)...

the second copy

pnlRight.Align:=alLeft;
pnlRight.Button1Click(Sender)...

How or is that possible? I think I need a Component of the full Panel, but I am not skilled enough to create a Component of this complexity yet.

I checked this how to copy all the TLabels parented with a TPanel on delphi to another TPanel?

and this Duplicating components at Run-Time

but don't think either will do what I need.

Thanks for anything you can help with.

1

1 Answers

6
votes

The solution to your problem does not lie in duplicating a control at run time. Instead, design a TFrame object. Put all your panel-specific code on there, including any controls it needs. Then, simply instantiate it twice, and give each one a different name. Then you can refer to LeftPanel.btnCheck and RightPanel.btnCheck.