I'm late. While typing my answer I saw JuhaManninen already posted an answer.
-----
@OP
So, you have made a customized form, why not show us the code. When talking about code related problem, it will be much easy for others to understand if you provide the code.
I saw you mentioned frame, were you talking about TForm or TFrame?
The first thing I noticed is that the form doesn’t use constructor and destructor keywords for the create and destroy methods generated through the object inspector.
Did you mean the OnCreate event and OnDestroy event?
Those events are not methods, they are variable.
For example, this is what happened if a form is being destroyed. The OnDestroy event is stored in FOnDestroy. The FOnDestroy will be process if it is assigned.
procedure TCustomForm.DoDestroy;
begin
try
if Assigned(FOnDestroy) then FOnDestroy(Self);
except
if not HandleDestroyException then
raise;
end;
end;
So, OnDestroy event is not a destructor.
If you want to 'fully' understand what constructor and destructor are, you need to understand the technical thing about OOP, what is VMT and why VMT is needed. That is too technical for most programmers. In short, constructor and destructor both needed to be called once.
When you code something like MyComponent := TMyComponent.Create, the constructor will be called because the Create is the constructor. But if you drop a component using the editor, the constructor and destructor will be handled automatically by Lazarus so you don't need to manually call the constructor and destructor.
There always more than one way to do the same thing in programming. Because you didn't provide your code here I show you the example of subclassing. Below is the example of a auto close form. Hope you can learn something form it.
TMyCustomFormunit MyCustomForm;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, StdCtrls, ExtCtrls;
type
{ TMyAutoCloseForm }
TMyAutoCloseForm = class(TForm)
private
FCounter: Integer;
FLabel: TLabel;
FTimer: TTimer;
procedure OnTimerEvent(Sender: TObject);
procedure ShowInfo;
public
constructor Create(TheOwner: TComponent; Duration: Integer); overload;
destructor Destroy; override;
procedure Show;
end;
implementation
{ TMyAutoCloseForm }
procedure TMyAutoCloseForm.OnTimerEvent(Sender: TObject);
begin
Dec(FCounter);
ShowInfo;
if FCounter <= 0 then
begin
FTimer.Enabled := False;
Close;
end;
end;
procedure TMyAutoCloseForm.ShowInfo;
var
S: string;
begin
case FCounter > 1 of
True: S := ' seconds';
False: S := ' second';
end;
FLabel.Caption := 'This form will close in' + LineEnding +
FCounter.ToString + S;
end;
constructor TMyAutoCloseForm.Create(TheOwner: TComponent; Duration: Integer);
begin
CreateNew(TheOwner);
Self.Left := 150;
Self.Top := 100;
FCounter := Duration;
FLabel := TLabel.Create(Self);
FLabel.Parent := Self;
FLabel.Left := 80;
FLabel.Top := 80;
FTimer := TTimer.Create(Self);
FTimer.Enabled := False;
FTimer.Interval := 1000;
FTimer.OnTimer := @OnTimerEvent;
end;
destructor TMyAutoCloseForm.Destroy;
begin
FTimer.Enabled := False;
FTimer.Free;
FLabel.Free;
inherited;
end;
procedure TMyAutoCloseForm.Show;
begin
inherited;
FTimer.Enabled := True;
ShowInfo;
end;
end.
Mainformunit Mainform;
{$mode objfpc}{$H+}
interface
uses
Classes, Forms, StdCtrls, ExtCtrls, MyCustomForm;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
with TMyAutoCloseForm.Create(Self, 5) do // form autoclose in 5 seconds
Show;
end;
end.