Thank you wp for your reply and the demo.
I am convinced that we use 'Application.ShowMainForm:=false' in a wrong way. What is the correct (intended) way
I guess it is needed for applications which are fully controlled by a tray icon - see the attached mini project as a demonstration. It creates the mainform with a TrayIcon, hides it (Application.ShowMainForm := false) and shows the trayicon which then takes control of the entire application.
This is a very interesting and important guess. If you are right then I wasted plenty of time to use something in a completely unsuitable way. I feel sad, that this important restriction is not clearly documented in
https://lazarus-ccr.sourceforge.io/docs/lcl/forms/tapplication.showmainform.htmlDear LCL Developers, can someone of you prove, that the intended use of 'Application.ShowMainForm:=false' is only for applications, which are fully controlled by a tray icon?I want to have a Main Form, because for me this is the easiest way to handle an INI-file).
Really? There is a class TIniFile which you must create, of course, and you add integers/strings/etx to it by calling the WriteInteger/WriteString/etc methods, and you get them back by calling the ReadInteger/ReadString/etc methods. And at the end you destroy the ini file. I think this *is* easy. And you can do this at any time, with/and without a Mainform.
Of course is it *possible* to handle an INI-file completely manually. But you have to read and to write each single property and beside integers and strings there are also more complex controls like e.g. ListBoxes etc. In my eyes this would be unneccessary effort. That's not worth it. I wrote in reply #8:
I have multiple projects where I want to use feature 'Application.ShowMainForm:=false' but if this feature would mean ... that e.g. the standard use of an INI-file via the Main Form is not longer possible, than this would be the wrong feature for me.
(in this case I would stay with my old "solution" from reply #12)
Application.Run() is only started at the moment, after the program had already finished, where this loop makes no more sense.
The need to avoid the Application.Run is a clear indication to me that you are using the Lazarus LCL GUI application in the wrong way.
I am convinced that jeremiah and me were using the Lazarus LCL GUI application in a wrong way, because this way Application.Run was useless, because it is started too late. I tried to explain this to jeremiah multiple times, but I fear, that he didn't understand this (and didn't test this). Maybe my English is too bad. The purpose of this Topic was to find out the correct way.
In fact, you should use a different application template. Simply use the "Simple Program" template which is the easiest type of application; it gives you full control over what is happening.
I created a new project with the "Simple Program" template. It's description in the IDE says: "A most simple Free Pascal command line program". By this description I would have expected a console program, not a GUI program. Then one very simple source file was created with only:
program Project1;
begin
end.
That's all. I tried the Help-Button in the 'Create a new project' dialog. Nothing happened. I used google to find a documentation, what the 9 different project templates mean and how they should be used, but I found nothing. To create a GUI application from this point I would have a lot of manual work by copying peace-by-peace from a "normal" GUI project, but that's not worth it.
Dear jeremiah, I had a look into your new code, but I had clearly written in reply #8:
To avoid misunderstandings:
I am not interested to find some workarounds / detours to handle an INI-file somehow nevertheless. I have multiple projects where I want to use feature 'Application.ShowMainForm:=false' but if this feature would mean ... that e.g. the standard use of an INI-file via the Main Form is not longer possible, than this would be the wrong feature for me. So please don't go in that direction.
Didn't you see that?
Summary: Dear LCL Developers, can someone of you prove the guess of wp, that the intended use of 'Application.ShowMainForm:=false' is only for applications, which are fully controlled by a tray icon?
Then I would close this Topic.