object Form1: TForm1
Left = 192
Top = 124
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 120
TextHeight = 16
object Button1: TButton
Left = 40
Top = 40
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click //删除此行
end
object Button2: TButton
Left = 136
Top = 40
Width = 75
Height = 25
Caption = 'Button2'
TabOrder = 1
OnClick = Button2Click //删除此行
end
object Panel1: TPanel
Left = 295
Top = 0
Width = 393
Height = 448
Align = alRight
BevelInner = bvRaised
BevelOuter = bvLowered
Caption = 'Panel1'
TabOrder = 2
end
object Memo1: TMemo
Left = 40
Top = 88
Width = 209
Height = 345
Lines.Strings = (
'Memo1')
TabOrder = 3
end
object OpenDialog1: TOpenDialog
Left = 16
Top = 208
end
end
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Panel1: TPanel;
OpenDialog1: TOpenDialog;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
FStream:TFileStream;
{ Public declarations }
end;
var
Form1: TForm1;
OutForm:TForm;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
FStream:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
FStream.Position :=0;
Memo1.Lines.LoadFromStream(FStream);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
TempForm:TForm;
StrMemo:TMemoryStream;
StrBin:TMemoryStream;
begin
StrMemo:=TMemoryStream.Create ;
Memo1.Lines.SaveToStream(strMemo);
StrBin:=TMemoryStream.Create ;
strMemo.Position :=0;
OBjectTextToResource(StrMemo,StrBin);
strBin.Position :=0;
TempForm:=TForm.Create (Application);
strbin.ReadComponentRes(TempForm);
OutForm:=TempForm;
//OutForm.BorderStyle:=bsNone;
OutForm.Parent:=Panel1;
OutForm.Left :=0;
OutForm.Top :=0;
OutForm.Show;
FStream.Free;
end;
initialization
RegisterClasses ([TButton, TMemo,TPanel,TOpenDialog]);
end.
上面的简单例子可以打开当前或其他dfm文件,记住在转换前从Memo中删除所有控件的事件属性,如上面的注释
以后你可以通过遍历所有的控件找到你要赋事件的控件,动态地赋给事件处理过程。