CSDN上的VCL高手何在???

whycats 2003-01-16 03:03:24
DELPHI 在存盘的时候会把你的窗体保存为.dfm文件格式
我想在代码中动态保存我的窗体(以.dfm的格式),该如何实现?
请大力支持!!
...全文
16 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
whycats 2003-01-16
  • 打赏
  • 举报
回复
TO: sweethzp(黄纸片)
oh my god!!!,谢谢你的帮助!
黄纸片 2003-01-16
  • 打赏
  • 举报
回复
从文件读出,这个是字符串生成对象
function StringToComponent(Value: string): TComponent;
var
StrStream:TStringStream;
BinStream: TMemoryStream;
begin
StrStream := TStringStream.Create(Value);
try
BinStream := TMemoryStream.Create;
try
ObjectTextToBinary(StrStream, BinStream);
BinStream.Seek(0, soFromBeginning);
Result := BinStream.ReadComponent(nil);
finally
BinStream.Free;
end;
finally
StrStream.Free;
end;
end;

注意,如果包含自己写的对象,请在单元的initialization调用RegisterClass,例:
initialization
RegisterClass(ThzpQRLabel);
RegisterClass(ThzpQRDBText);
end;
rwdx 2003-01-16
  • 打赏
  • 举报
回复
up
黄纸片 2003-01-16
  • 打赏
  • 举报
回复
这个好办,用下面函数得到string,然后保存到文件
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;
liuxiaowei 2003-01-16
  • 打赏
  • 举报
回复
参考帮助里面的:streaming utilities
Read之前需要RegisterClass
liuxiaowei 2003-01-16
  • 打赏
  • 举报
回复
WriteComponentResFile procedure:
Writes components and their properties to a file using a resource file format.

ReadComponentRes function:
Reads components and their properties from a specified resource.

ReadComponentResEx function:
Reads a component from a resource.

ReadComponentResFile function:
Reads components and their properties from a specified Windows resource file.
murphy 2003-01-16
  • 打赏
  • 举报
回复
建议:
学习ToolsAPI,应该有方法吧?!
思路:
GetProjectGroup ——> ActiveProject ——> ...
再往下就看你的了!(找到Active的单元,获得想对应的dfm---应该是流,Save之!)

祝你成功!
要是成了记得告知一下!学习学习!

好运!
:)
singlesword 2003-01-16
  • 打赏
  • 举报
回复
这个好像不行吧?
dfm是在编译的时候用的啊。
你可以把自己窗体的参数写到文件里啊。

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧