首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何保存和加载TFrame内容?

如何保存和加载TFrame内容?
EN

Stack Overflow用户
提问于 2021-06-29 07:49:15
回答 1查看 157关注 0票数 2

我使用以下代码保存和加载我的表单:

代码语言:javascript
运行
复制
public
  constructor Create(AOwner: TComponent); override; 
  procedure BeforeDestruction; override; 

var
  PreservePath: String;

constructor TMyForm.Create(AOwner: TComponent);
begin   
  PreservePath := ExtractFilePath(Application.ExeName) +
    'Preserve';
  if not DirectoryExists(PreservePath) then
    CreateDir(PreservePath);
    PreservePath := PreservePath + '\';
  if FileExists(PreservePath + ClassName + '.sav') then
  begin
    CreateNew(AOwner, 0);
    with TFileStream.Create(PreservePath + ClassName + '.sav',
                            fmOpenRead or fmShareDenyWrite) do
    try
      ReadComponent(Self);
    finally
      Free;
    end;
  end;
end;

procedure TMyForm.BeforeDestruction;
begin
 inherited;
    with TFileStream.Create(PreservePath + ClassName + '.sav',
                            fmCreate) do
  try
    WriteComponent(self);
  finally
    Free;
  end;
end;

它对表单很好,但是当尝试对TFrame做同样的操作时,它不工作,因为它没有CreateNew过程。如何保存和加载此帧?特别是如果它包含动态创建的控件。

Windows 7,Delphi 7。

EN

回答 1

Stack Overflow用户

发布于 2022-05-03 07:52:34

您可以重写框架的创建/销毁过程:

代码语言:javascript
运行
复制
   type MyFrame = class(TFrame)
    ...
   public
       { Déclarations publiques }
       constructor create(AOwner: TComponent);override;
       destructor destroy;override;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68174577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档