Delphi中是否提供将Form存储为Dfm的函数?(100分)

  • 主题发起人 主题发起人 xiangfan_zhangk
  • 开始时间 开始时间
X

xiangfan_zhangk

Unregistered / Unconfirmed
GUEST, unregistred user!
Delphi中是否提供将Form存储为Dfm的函数?
 
Delphi自带的Example:

function ComponentToString(Component: TComponent): string;
var
BinStream:TMemoryStream;
StrStream: TStringStream;
s: string;
begin
BinStream := TMemoryStream.Create;
try
StrStream := TStringStream.Create(s);
try
BinStream.WriteComponent(Component);
BinStream.Seek(0, soFromBeginning);
ObjectBinaryToText(BinStream, StrStream);
StrStream.Seek(0, soFromBeginning);
Result:= StrStream.DataString;
finally
StrStream.Free;

end;
finally
BinStream.Free
end;
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.Text := ComponentToString(Self);
end;
 
WriteComponentResFile('d:/Form1.dfm', Form1);
 
多人接受答案了。
 
用WriteComponentResFile可以写,但是如何读啊?
Sachow帮帮忙,谢谢了
 
procedure TForm1.FormDblClick(Sender: TObject);
begin
try
//读入窗体文件"TestForm1.rfm",在读入之前必须删除窗体上的所有控件,否则会由控件
//重名而出错
while ComponentCount>0 do
Components[0].Free;
ReadComponentResFile('TestForm1.rfm', Form1);
except
end;
end;
 
后退
顶部