|
The UNITS CHANGEOWNER code is as follows:
program CHANGEOWNER;
uses
Forms,
YUANLAI in 'YUANLAI.pas' {Form1},
HOULAI in 'HOULAI.pas' {Form2};
{$ R * .res}
begin
Application.Initialize;
Application.CreateForm (TForm1, Form1);
Application.CreateForm (TForm2, Form2);
Application.Run;
end.
The UNITS YUANLAI code is as follows:
unit YUANLAI;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class (TForm)
ButtonCHG: TButton;
Button1: TButton;
ButtonLIST: TButton;
ListBox1: TListBox;
procedure Button1Click (Sender: TObject);
procedure ButtonLISTClick (Sender: TObject);
procedure ButtonCHGClick (Sender: TObject);
private
{Public declarations}
public
{Public declarations}
end;
var
Form1: TForm1;
implementation
USES HOULAI;
{$ R * .dfm}
procedure TForm1.Button1Click (Sender: TObject);
begin
ShowMessage ('My owner is' + ((Sender as TButton) .Owner as TForm) .Name);
end;
procedure TForm1.ButtonLISTClick (Sender: TObject);
var i: Integer;
begin
self.ListBox1.Items.Clear;
for i: = 0 to Componentcount-1do
begin
self.ListBox1.Items.Add (Components [i] .Name);
end;
end;
procedure change (com, newowner: TComponent);
begin
com.Owner.RemoveComponent (com);
newowner.InsertComponent (com);
end;
procedure TForm1.ButtonCHGClick (Sender: TObject);
begin
if Assigned (self.Button1)
then
self.Button1.Parent: = Form2;
change (Button1, Form2);
end;
end.
The UNINTS HOULAI code is as follows:
unit HOULAI;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class (TForm)
ButtonLIST: TButton;
ListBox1: TListBox;
procedure ButtonLISTClick (Sender: TObject);
private
{Private declarations}
public
{Public declarations}
end;
var
Form2: TForm2;
implementation
{$ R * .dfm}
procedure TForm2.ButtonLISTClick (Sender: TObject);
var i: Integer;
begin
self.ListBox1.Items.Clear;
for i: = 0 to Componentcount-1do
begin
self.ListBox1.Items.Add (Components [i] .Name);
end;
end;
end.
thanks, thanks! |
|