: {
: HELP !
: F1!
: F1!
: }
: unit Unit1;
:
: interface
:
: uses
: Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
: Dialogs, StdCtrls;
:
: type
: TForm1 = class(TForm)
: Button1: TButton;
: Button2: TButton;
: procedure Button1Click(Sender: TObject);
: procedure Button2Click(Sender: TObject);
: private
: { Private declarations }
: public
: { Public declarations }
: end;
:
: var
: Form1: TForm1;
: btn: array of TButton;
: nr_btn: word;
:
: implementation
:
: {$R *.dfm}
:
: procedure TForm1.Button1Click(Sender: TObject);
: begin
: {Here create a Button}
: if nr_btn < 10 then begin
: setlength(btn,nr_btn+1);
: btn[nr_btn] := TButton.Create(Application);
: btn[nr_btn].Left := nr_btn*5;
: btn[nr_btn].Top := nr_btn*5;
: btn[nr_btn].Caption := '&'+inttostr(nr_btn)+' Btn Created';
: btn[nr_btn].Parent := Form1;
: btn[nr_btn].Name := 'btn'+inttostr(nr_btn);
: inc(nr_btn);
: end
: else messagedlg('Max nr_btn!',mtInformation,[mbOk],0);
: end;
:
: procedure TForm1.Button2Click(Sender: TObject);
: begin
: {Here copy a button ????}
: if (nr_btn < 10)and(nr_btn<>0) then begin
: setlength(btn,nr_btn+1);
: btn[nr_btn] := TButton.Create(Application);
: btn[nr_btn].Assign(btn[0]); //Here raise an error
: {
: Error: Cannot assign a TButton to a TButton
: How to Copy
: }
: inc(nr_btn);
: end
: else messagedlg('Arghhh !',mtError,[mbOk],0);
: end;
:
: end.
:
:
You'll have to copy each of the relevant property and event values by hand, which is in your case the Left, Top, Caption and Parent.
Note: each of the component's owner isn't the Application, but the Form on which it is placed. This could be important, when naming the component, since each name must be unique in the owner's list.