Jump to content
IElite

intialization & finalization

Recommended Posts

In Delphi,

 

If I have a unit and I have code in the initialization and finalization sections, 

 

the initialization code gets called when the unit is loaded on startup

 

and

 

 and finalization code gets called when the application terminates and unloads the unit

 

 

 

this does not seem to be whats happening in SMS

 

it seems that the 

 

 finalization code gets called when the application completes loading

 

initialization
 ShowMessage('initialize');


finalization
 ShowMessage('finalize');

 

Share this post


Link to post
Share on other sites
further info:

SEQUENCE INITIALIZATION OF THE SMARTMS APPLICATION

===============================================

Hi, there. I've created a visual form based application with 3 forms, here is the sequence I'm getting: 

 

 

01. { initialization section of the units }

    ||

    ||

    \/


// the initialization section is a good place initialize values of runtime objects, create instances of global objects

// The first load will initialize all registered forms and custom units in the initialization section.

initialization UBaseClass 

TForm1 initialization 

TForm2 initialization 

TForm3 initialization 

TApplication initialization 

 


02. { procedure TApplication.ApplicationStarting; }


    ||

    ||

    \/

// OK. This will call the method InitializeObject to all registered forms. Each form, I've created a instance of TPage.

 

TForm1.InitializeObject 

TPage.create1 


Page was called1 

 

TPage.create2 

Page was called2 

 

TForm2.InitializeObject 

TForm3.InitializeObject 

 

TPage.create3 

Page was called3 

 

03. { call RESIZE event Main Form}


    ||

    ||

    \/


// Page reflow issue:

// I think the bottleneck is coming from the Resize event. Resize is firing multiple times, and this will reduce the // browser's workload. I think this is a potencial performance bottleneck.

// It appears relatively straight forward, however when I re-size the browser window, I get two successive on

// Resize firing all the time.

 


TForm1.Resize 


TForm1.Resize 

 

04. { call InitializeForm Main Form}


    ||

    ||

    \/

// ah, it will call the method initializeForm of the Main form

TForm1.InitializeForm 


 

05. { call resize event Main Form}


    ||

    ||

    \/

// it will call another resize

TForm1.Resize 


 

06. { call FormActivate event Main Form}

    ||

    ||

    \/

TForm1.FormActivated 

 

07. { call procedure TApplication.ApplicationStarted }


    ||

    ||

    \/

// After all registered forms have been initialized, this method is called:

TApplication.ApplicationStarted


 

08. { call finalization section of all units }  <<<==============  finalization section was called


// The finalization section can perform clean-up actions, for example:

//Release references to objects,

// Free resources allocated within the initialization routine

// It seems there are issues freeing resources allocated within the initialization section

    ||

    ||

    \/

TApplication finalization 


TForm3 finalization 

TForm2 finalization 

TForm1 finalization 

finalization UBaseClass 

 

09. { call resize event to all registered forms}

    ||

    ||

    \/

// this is probably causing page reflows. The resize event will trigger the browser to synchronously calculate the // style and layout.

TForm2.Resize   // the second form

TForm3.Resize   // the third form

TForm1.Resize   // the main Form - the last

 

10. { call the method ObjectReady to all registered forms}

    ||

    ||

    \/

TForm1.ObjectReady 

TForm2.ObjectReady 

TForm3.ObjectReady


    ||

    ||

    \/

THE END


----------------------------------------------------------

 

 

< BUTTON1 > //--- on button click event: Application.GotoForm('Form2'); 

 

TForm1.FormDeActivated 

TForm2.Resize 

TForm2.InitializeForm 

TForm2.Resize 

TForm2.FormActivated 

 

----------------------------------------------------------

< BUTTON2 >  //--- on button click event: Application.GotoForm('Form3'); 

TForm2.FormDeActivated 

TForm3.Resize 

TForm3.InitializeForm 

TForm3.Resize 

TForm3.FormActivated 

 

----------------------------------------------------------

< BUTTON3 >  //--- on button click event: Application.GotoForm('Form1'); {back to Form1}

 

TForm3.FormDeActivated 

TForm1.Resize 

TForm1.FormActivated

 

----------------------------------------------------------

< BUTTON3 >  //--- on button click event: Application.Terminate();

    ||

    ||

    \/ 

will trigger the method:

TApplication.ApplicationClosing; 

 


    ||

    ||

    \/

// release all objects


TPage.Destroy; 

TForm1.FinalizeObject;

 

TPage.Destroy;

TForm2.FinalizeObject;

 

TPage.Destroy;

TForm3.FinalizeObject;

 


    ||

    ||

    \/

 

the end;

Share this post


Link to post
Share on other sites
08. { call finalization section of all units }  <<<==============  finalization section was called
// The finalization section can perform clean-up actions, for example:
//Release references to objects,
// Free resources allocated within the initialization routine
// It seems there are issues freeing resources allocated within the initialization section
    ||
    ||
    \/
TApplication finalization 
TForm3 finalization 
TForm2 finalization 
TForm1 finalization 
finalization UBaseClass 

 

Hi WarelyAlex,

 

I am referring to a unit that does not have a form.

 

I was using it just to declare the LocalStorage var and initialize it and finalize it 

 

I was just curious as to why the finalization was not kicked off like it is in Delphi.

 

Shane

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×