Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Share:
Notifications
Clear all

[Solved] Lazarus - How to start an application with the main form hidden?

1 Posts
1 Users
0 Reactions
4,927 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

I have an application that is going to be living in the SysTray (or on the Mac: in the menu bar) and I really don't like my users to see the mainform when they start the application - the idea being that the application should automatically start when the computer starts.

So after some searching I found a solution that does the trick (Lazarus Forum).

Simply open your project file (the .lpr file) - this can be done directly or by clicking the "Project" menu, choose "Project Inspector" and under files double click the ".lpr" file.

In the project code add the line "Application.ShowMainForm:=FALSE" right before the "Application.CreateForm()" line.
This will prevent the main form to show at startup - I have tested this under Windows and MacOS X and it works.

For example:

program ExmpleProg;
{$mode objfpc}{$H+}
uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms, mainunit
  { you can add units after this };
{$R *.res}
begin
  RequireDerivedFormResource := True;
  Application.Initialize;
  Application.ShowMainForm := FALSE; // <- this line prevents the window from showing
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.          

   
ReplyQuote
Share: