Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 311457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:55:36+00:00 2026-05-12T07:55:36+00:00

I have a TPanel pnlMain, where several dynamic TPanels are created (and pnlMain is

  • 0

I have a TPanel pnlMain, where several dynamic TPanels are created (and pnlMain is their Parent) according to user actions, data validations, etc. Every panel contains one colored grid full of strings. Apart from panels, there are some open source arrows components and a picture. Whole bunch of stuff.

Now I want user to be able to print this panel (I asked how to do it on this question), but before printing, user must be presented with a new form, containing copy of pnlMain. On this form user has to do some changes, add few components and then print his customized copy of pnlMain. After printing user will close this form and return to original form with original pnlMain. And – as you can guess – original pnlMain must remain intact.

So is there any clever way to copy whole TPanel and it’s contents? I know I can make it manually iterating through pnlMain.Controls list.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:55:36+00:00Added an answer on May 12, 2026 at 7:55 am

    Code based as iterating on child controls, but not bad in anyway 😉

    procedure TForm1.btn1Click(Sender: TObject);
    
        function CloneComponent(AAncestor: TComponent): TComponent;
          var
            XMemoryStream: TMemoryStream;
            XTempName: string;
          begin
            Result:=nil;
            if not Assigned(AAncestor) then
              exit;
            XMemoryStream:=TMemoryStream.Create;
            try
              XTempName:=AAncestor.Name;
              AAncestor.Name:='clone_' + XTempName;
              XMemoryStream.WriteComponent(AAncestor);
              AAncestor.Name:=XTempName;
              XMemoryStream.Position:=0;
              Result:=TComponentClass(AAncestor.ClassType).Create(AAncestor.Owner);
              if AAncestor is TControl then TControl(Result).Parent:=TControl(AAncestor).Parent;
              XMemoryStream.ReadComponent(Result);
            finally
              XMemoryStream.Free;
            end;
          end;
    
        var
          aPanel: TPanel;
          Ctrl, Ctrl_: TComponent;
          i: integer;
        begin
          //handle the Control (here Panel1) itself first
          TComponent(aPanel) := CloneComponent(pnl1);
          with aPanel do
          begin
            Left := 400;
            Top := 80;
          end;
    
          //now handle the childcontrols
          for i:= 0 to pnl1.ControlCount-1 do begin
            Ctrl := TComponent(pnl1.Controls[i]);
            Ctrl_ := CloneComponent(Ctrl);
            TControl(Ctrl_).Parent := aPanel;
            TControl(Ctrl_).Left := TControl(Ctrl).Left;
            TControl(Ctrl_).top := TControl(Ctrl).top;
          end;
        end;
    

    code from Delphi3000 article

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several TPanels that are populated with buttons at runtime. However the code
I have a wide TPanel with several buttons on it (essentially a tool bar).
I have TPanel. On this Panel there is an TImage descendant , few other
I have a Delphi 2007 VCL TPanel with a TPopupMenu assigned to it. There
I need to draw on a TPanel, ideally directly so I don't have another
Have you ever created or encountered a self modifying code in Java? If yes,
I have a TabControl, and I am using a TPanel to group my controls
Have a simple contact us XPage created. Have server side validation in place that
There are several third-pary controls (such as the Raize Components ) which have a
Have advancements in CPU design like dynamic instruction scheduling narrowed the performance gap between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.