我使用以下代码保存和加载我的表单:
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,德尔福 7。