UNITS CHANGEOWNER 代码如下:
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.UNITS YUANLAI代码如下:
unit YUANLAI;interfaceuses
  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;implementationUSES 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.UNINTS HOULAI 代码如下:
unit HOULAI;interfaceuses
  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.
谢谢 ,谢谢!

解决方案 »

  1.   

    begin
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.CreateForm(TForm2, Form2);
      Form2.show;
      Application.Run;
    end.
      

  2.   

    application 创建相应的窗体后默认Show出第一个创建的窗体(主窗体),你可以像dovelee() 那样将Form2显示出来,也可以在主窗体显示的时候打开Form2
      

  3.   

    可以,方法多的是,楼上也是方法,你也可以在form1的onshow事件里写form2.show
      

  4.   

    可以启动两个窗口了 不过还有个问题啊 我如果连续的点击那个CHANGE按钮  就会出现EXCEPTION 麻烦给我结实一下  谢谢