'How to save & load TFrame contents?

I use the following code to save & load my Form:

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;

it works fine for the Form but when trying to do the same with TFrame it's not working as it doesn't have the CreateNew procedure. How do I save & load this Frame? Especially if it contains dynamically created controls.

Windows 7, Delphi 7.



Solution 1:[1]

You can override Create / Destroy procedure of a Frame :

   type MyFrame = class(TFrame)
    ...
   public
       { Déclarations publiques }
       constructor create(AOwner: TComponent);override;
       destructor destroy;override;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Louk Oum