Recent

Author Topic: In an application, how do you have a main function that is executed when the app  (Read 1612 times)

vonskie

  • Full Member
  • ***
  • Posts: 184
In an application, how do you have a main function that is executed when the app loads?



balazsszekely

  • Guest
@vonskie
Quote
In an application, how do you have a main function that is executed when the app loads?
I suppose you're talk about a GUI application(File-->New-->Project-->Application). First take a look at the life cycle of a form: http://wiki.freepascal.org/Event_order#Lazarus_documentation . You can choose the first three event to call your "main function". Each event is explained in details, you can pick the one who fits your needs best.

minesadorada

  • Sr. Member
  • ****
  • Posts: 452
  • Retired
Here is a typical LPR (project) file.
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Interfaces, // this includes the LCL widgetset
  10.   Forms, unit1
  11.   { you can add units after this };
  12.  
  13. {$R *.res}
  14.  
  15. begin
  16.   RequireDerivedFormResource:=True;
  17.   Application.Initialize;
  18.   Application.CreateForm(TForm1, Form1);
  19.   Application.Run;
  20. end.      

As you can see it starts with the keyword program and has a uses section which includes the bare minimum needed to run a GUI application.

It then runs code between the begin and end. keywords, which would be the equivalent of a main() function perhaps.  The event loop is contained in the Application object.
GPL Apps: Health MonitorRetro Ski Run
OnlinePackageManager Components: LazAutoUpdate, LongTimer, PoweredBy, ScrollText, PlaySound, CryptINI

 

TinyPortal © 2005-2018