Vikas
Vikas

Reputation: 89

How to free TFrame after closing

When we close a frame, it is not freed, it still remains in the memory and it is still assigned.

How to track OnClose event of TFrame, to be able to free the frame?

Upvotes: 3

Views: 2508

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 598134

TFrame has no OnClose event. You have to implement and track that manually. However, when you are ready to free the Frame object, you can do what TForm.Release() does - post a custom message to yourself and then free the object in the message handler. For example:

type
  TMyFrame = class(TFrame)
  private
    procedure CMRelease(var Message: TMessage); message CM_RELEASE;
  public
    procedure Release;
  end;

procedure TMyFrame.CMRelease(var Message: TMessage);
begin
  Free;
end;

procedure TMyFrame.Release;
begin
  PostMessage(Handle, CM_RELEASE, 0, 0);
end;

Just call Release() when you need to free the Frame, and it will free itself at its earliest convenience.

Upvotes: 4

Related Questions