先创建一个FRAME,为UNIT2
////
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TFrame2 = class(TFrame)
Panel1: TPanel;
Button1: TButton; //在PANLE1上
Edit1: TEdit; //在PANLE1上
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
{$R *.dfm}
end.
/////////////////////////
在要调用的地方引用这个单元,再动态创建赋值就好了
////
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button2: TButton;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
var
f:TFrame2;
begin
f:=TFrame2.Create(self);
f.Parent:=Self; ////动态创建赋值
f.Visible:=True;
f.Button1.Caption:='UserName';
end;
end.
//////////////////
这样就可以达到你要的效果