Recent

Author Topic: OK to use the .lpr file to put pasca code there?  (Read 5219 times)

Elmug

  • Hero Member
  • *****
  • Posts: 849
OK to use the .lpr file to put pasca code there?
« on: July 23, 2011, 03:34:19 am »
I've been curious on asking this:

The editor can open the .lpr file which is the Pascal Program and has statements on running "the application".

I wonder if code can be put in there, and if so, what'd be a potential use for that?

Thanks!

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: OK to use the .lpr file to put pasca code there?
« Reply #1 on: July 23, 2011, 03:50:05 am »
Quote
I wonder if code can be put in there

Yes.

Quote
what'd be a potential use for that?

For example, code you want to be executed before creating any form.

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: OK to use the .lpr file to put pasca code there?
« Reply #2 on: July 23, 2011, 04:00:57 am »
What is the order of execution during a startup?

.lpr runs first, I assume.
How does the program know to show the main window first and not all of them?
How does Application.Run know what to start first?
From help:  "Run is the start of the user code: when called, it starts a loop and repeatedly calls DoRun until Terminated is set to True"

Code: [Select]
begin
  Application.Initialize;
  Application.CreateForm(TfRIMMain, fRIMMain);
  Application.CreateForm(TfAbout, fAbout);
  Application.CreateForm(TfDebug, fDebug);
  Application.CreateForm(TfImport, fImport);
  Application.CreateForm(TfIPRef, fIPRef);
  Application.CreateForm(TfReg, fReg);
  Application.CreateForm(TfOptions, fOptions);
  Application.CreateForm(TfSNMPGet, fSNMPGet);
  Application.Run;

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: OK to use the .lpr file to put pasca code there?
« Reply #3 on: July 23, 2011, 04:06:51 am »
I gather Typo is saying that regular pascal code can be put anywhere if it makes sense, and I suppose that the code in the .lpr would be done in a sequential order as it has it, but maybe code put in there could change the order. But I am supposing and need to be corrected if not right.

Also I'd like to know if one puts statements in the .lpr and one recompiles, I suppose one's statements would be respected, meaning the .lpr file is not done anew every time?

Thanks!

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: OK to use the .lpr file to put pasca code there?
« Reply #4 on: July 23, 2011, 04:10:50 am »
Quote
I suppose one's statements would be respected,

Yes.

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: OK to use the .lpr file to put pasca code there?
« Reply #5 on: July 23, 2011, 04:15:19 am »
As an example, I now pondering putting my program license check in the .lpr unit.  That way I can validate the program options based on the license key and if there is a bad key, I can shut down the program before showing any of the windows.

Elmug, In a prior thread, I was also given the same advise (probably by typo) that I could put any code in the .lpr unit.

Next question - how many people do put code into .lpr file and if so, what program functions do they put there? 

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: OK to use the .lpr file to put pasca code there?
« Reply #6 on: July 23, 2011, 08:34:36 am »
This discussion helped me a lot to understand more on what's going on.

I'm glad I asked, and more so for the great replies.

Thanks everyone.

 

TinyPortal © 2005-2018