whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

10 Visitors Online


 
...clone a Component?
Autor: P. Below
Homepage: http://www.teamb.com
[ Print tip ]  

Tip Rating (17):  
     


{ This code shows how to clone a TPanel (Panel1)
  You can do it with any other component

  Dieser Code zeigt, wie ein TPanel (Panel1) geklont
  werden kann. Das funktioniert natürlich auch mit
  anderen Komponenten
}

procedure TForm1.Button1Click(Sender: TObject);
var
  
ms: TMemoryStream;
  s: string;
  p, temp: TPanel;
  x,y: Integer;
begin
  
ms := TMemoryStream.Create;
  try
    
temp := panel1;
    s := panel1.Name;
    panel1.Name := '';
    try
      
ms.WriteComponent(temp);
      ms.Position := 0;
      p := TPanel.Create(Self);
      ms.ReadComponent(p);
      with do
      begin
        
x := panel1.Left;
        y := panel1.Top;
        Inc(x, 5);
        Inc(y, 5);
        SetBounds(x, y, Width, Height);
        Parent := Self;
        Name := Format('Panel%d_%d', [x, y]);
      end;
    finally
      
temp.Name := s;
      panel1 := temp;
    end
  finally
    
ms.Free;
  end{ finally }
end;



 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners