Correct way to close a form lazarus / 21-General ---------------------------------------------------------------------- lander · 2021-10-05 06:51 Hi, I have searched on google already and there are various ways to close a form but I'm confused. Which is the correct way to open Form2 and close Form1 freeing the space from memory? ---------------------------------------------------------------------- Handoko · 2021-10-05 07:17 Hello lander, Welcome to the forum. If Form1 is the mainform, you should not close it. Closing mainform will terminate the program. Instead, you can hide the mainform before showing the Form2. ---------------------------------------------------------------------- lander · 2021-10-05 07:24 Thank you for your fast reply. And to correctly close the second form as mentioned in first post? Form2.Destroy, .Free or .Close? Instead for the first form I can just do .Hide? ---------------------------------------------------------------------- Zvoni · 2021-10-05 09:50 Never ever call the "Destroy"-Method (of any Class) directly. And just use "sane" thinking: You exit your car you CLOSE the door you lock your car, FREEing your mind so you don't have to fret about it if someone is going to steal it ---------------------------------------------------------------------- Handoko · 2021-10-05 09:51 Below is a demo doing the thing OP said. Here you can learn: - How to create a splash screen - Loading image from application resources Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit uniForm1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, ExtCtrls, StdCtrls, uniForm2; type   { TForm1 }   TForm1 = class(TForm)    Label1: TLabel;    Timer1: TTimer;    procedure FormCreate(Sender: TObject);    procedure FormDestroy(Sender: TObject);    procedure FormPaint(Sender: TObject);    procedure Timer1Timer(Sender: TObject);  private    FDelay: Integer;    FBackground: TBitmap;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);var  Stream: TResourceStream;  Image:  TImage;begin  // Make it center and borderless  BorderStyle := bsNone;  Position    := poScreenCenter;  // Get the background image from application resource  FBackground := TBitmap.Create;  Stream      := TResourceStream.Create(HInstance, 'BACKGROUND', RT_RCDATA);  Image       := TImage.Create(nil);  Image.Picture.LoadFromStream(Stream);  FBackground.Assign(Image.Picture.Bitmap);  Image.Free;  Stream.Free;  // Prepare the timer  FDelay         := 5;  Label1.Caption := FDelay.ToString;end; procedure TForm1.FormDestroy(Sender: TObject);begin  FBackground.Free;end; procedure TForm1.FormPaint(Sender: TObject);begin  Canvas.Draw(0, 0, FBackground);end; procedure TForm1.Timer1Timer(Sender: TObject);begin  // Show the countdown  Dec(FDelay);  Label1.Caption := FDelay.ToString;  if FDelay > 0 then Exit;  // Hide the form  Timer1.Enabled := False;  Visible        := False;  Form2.Show;end; end. - Form1 now becomes a splash form - You should treat Form2 as a mainform - But closing Form2 won't automatically terminate the program Because system does not know Form2 should be treated as mainform, closing it will not automatically terminate the program. You need to manually terminate it. Try running the demo, uncheck the checkbox and close the form to see what will happen. There many different ways to create a splash screen, you can search the forum learn how others do it. ---------------------------------------------------------------------- marcov · 2021-10-05 14:36 I'm no GUI hero, but afaik it depends how your form was created. Autocreated forms are registered with application and released with them. (application.createform). Manual will have NIL as parent, and can just be closed and free. Don't forget to disable any events coming into the form before doing that. ---------------------------------------------------------------------- lander · 2021-10-06 18:14 Thanks for your help.