Recent

Author Topic: OnImmediatelyAfterCreate  (Read 1038 times)

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
OnImmediatelyAfterCreate
« on: May 26, 2020, 08:23:19 am »
Hello!

What is the best way to make a procedure what runs after OnCreate but before any other things and I can write here what I can't put in OnCreate?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: OnImmediatelyAfterCreate
« Reply #1 on: May 26, 2020, 09:21:26 am »
What is your usecase here? Why do you think you need this?

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: OnImmediatelyAfterCreate
« Reply #2 on: May 26, 2020, 09:33:16 am »
What is your usecase here? Why do you think you need this?
That's actually common practice, that devs have to use some sort of OnActivate in order to write some code, that doesn't work inside OnCreate, because form's window isn't fully created. It's obvious crutch. He talks about some event, that triggers immediately after WM_CREATE. I.e. event, that triggers right at the end of CreateForm. For example here:
Code: Pascal  [Select][+][-]
  1.   Application.Initialize;
  2.   Application.CreateForm(TForm1, Form1);
  3.   <<<<<Insert your code here
  4.   Application.Run;    
  5.  
« Last Edit: May 26, 2020, 09:35:36 am by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: OnImmediatelyAfterCreate
« Reply #3 on: May 26, 2020, 09:37:52 am »
What is your usecase here? Why do you think you need this?
That's actually common practice, that devs have to use some sort of OnActivate in order to write some code, that doesn't work inside OnCreate, because form's window isn't fully created. It's obvious crutch. He talks about some event, that triggers immediately after WM_CREATE. I.e. event, that triggers right at the end of CreateForm. For example here:

Yes, but it's better to know Jake012345's usecase so that we can steer them in the right direction.

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: OnImmediatelyAfterCreate
« Reply #4 on: May 26, 2020, 09:51:50 am »
I making a Map editor form my game and I want to create a Shape for resizing the Images: (Attachment)

And I want to set it the selected image's right bottom corner but I want to create it once, just 'teleport'.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: OnImmediatelyAfterCreate
« Reply #5 on: May 26, 2020, 12:54:18 pm »
down in the bottom of one of your units in the Initialization Section create that image as a stand alone
image.

And in the finalization section free it.
have the Variable for it in the interface.

 if this image is going to be shared among multiple units then I would suggest you place this image in those sections in a unit marked as common, meaning this unit will be referenced from all other units in your program.

 This same unit can also hold common data and functions used in all of your other units, too.

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018