Forum > Beginners

Curious about how TForm's instant instantiate it's field member.

(1/1)

LittleRabbit:
Hello All.

I'm super newbie, teaching myself programming in the hope of to be able to build an application for my personal use.
I'm studying free pascal/ lazarus.

Starting with standard lazarus application project, the lazarus automatically generated code skeleton, and i  added a button to the form, then the code looked like this

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} end. 
My questions are :
1. Where did the constructor of the Form1 is called? , in Application.CreateForm(TForm1, Form1); ?
2. How constructor of Form1 object call constructor of Button1 without the need to
override the constructor of TForm?

Thank you.

lucamar:

--- Quote from: LittleRabbit on June 26, 2021, 07:27:44 am ---1. Where did the constructor of the Form1 is called? , in Application.CreateForm(TForm1, Form1); ?
--- End quote ---

That's not the constructor per se but yes, it's where the form's Create() is called among other things ... which lead us to:


--- Quote ---2. How constructor of Form1 object call constructor of Button1 without the need to
override the constructor of TForm?
--- End quote ---

It's not the "constructor" of the form but the CreateForm() method of TApplication. Very, very basically, after some convolutions and among other things, the form resource (let's say, the .lfm embedded in the program) is read, the form's properties set from it, controls and components (classes) read, instances created and properties set from it, etc.

LittleRabbit:
Thank you very very much , lucama.
Lazarus team is very clever.

GUI is so complex.  %)

Navigation

[0] Message Index

Go to full version