Creating a Button
var Button_1 : TButton; // this makes it global procedure TForm1.Button1Click(Sender: TObject); begin Button_1 := TButton.Create(self); Button_1.Top := 40; Button_1.Left := 40; Button_1.Parent := self; Button_1.Caption := 'test'; end;
Linking to a Component on Another Form
var Button_1 : TButton; // this makes it global procedure TForm1.Button1Click(Sender: TObject); begin Button_1 := Form2.Button1; Button_1.Parent := self; // Will not display without this end; // This example does not require a global constant procedure TForm1.Button2Click(Sender: TObject); begin Form2.Button1.Parent := self; // Will not display without this end;
Linking Tabsheets from Another Form
In this example, a tabbed control was created on each of 2 pages. Only one page was displayed, the other stayed hidden. When the button was clicked, the tab sheet on the hidden page was displayed on the main page.
Notice that for Tabsheets, the parent should be a PageControl ... not the Form.
procedure TForm1.Button1Click(Sender: TObject); begin Form2.TabSheet1.Parent := PageControl1; end; procedure TForm1.Button2Click(Sender: TObject); begin TabSheet1 := Form2.TabSheet1; TabSheet1.Parent := PageControl1; end;This has the advantage that a single line of code causes Form1 to display all the components on Form2.TabSheet1 ... even the underlying code is executed when a button on Form2.TabSheet1 in clicked.
TPersistent.Assign
var Button_1 : TButton; // this makes it global procedure TForm1.Button2Click(Sender: TObject); begin Button_1:= TButton.Create(self); Button_1.Assign(Button2); // This fails end;This is from the Delphi 5 TPersistent.Assign help
In general, the statement “Destination := Source” is not the same as the statement “Destination.Assign(Source)”. The statement “Destination := Source” makes Destination reference the same object as Source, whereas "Destination.Assign(Source)" copies the contents of the object referenced by Source into the object referenced by Destination.Author: Robert Clemenzi - clemenzi@cpcug.org