我使用以下代码保存和加载我的表单:
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。
发布于 2022-05-03 07:52:34
您可以重写框架的创建/销毁过程:
type MyFrame = class(TFrame)
...
public
{ Déclarations publiques }
constructor create(AOwner: TComponent);override;
destructor destroy;override;https://stackoverflow.com/questions/68174577
复制相似问题