Recent

Author Topic: Hide Mainform and restart?  (Read 2854 times)

dietmar

  • Full Member
  • ***
  • Posts: 170
Hide Mainform and restart?
« on: April 23, 2015, 08:47:19 pm »
Hello,

I have a program that should be "customized" on the first run after installation. What I want is to hide the Mainform, only show a modal dialog in which the user can setup the basic application "behaviour", and after that a config file is written and the application restarts - now showing the customized Mainform.

I tried with form.hide, form.visible, but got runtime errors...
What is the best way to to this and to restart the application afterwards?

Thx in advance,
Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

BitBangerUSA

  • Full Member
  • ***
  • Posts: 183
Re: Hide Mainform and restart?
« Reply #1 on: April 23, 2015, 09:02:58 pm »
you might want to post more details about the errors you get and your program code.

the Lazarus/FPC code controlling Form status should not be causing the problem - likely something in your code is.

have you considered having a separate config app?
Lazarus Ver 2.2.6 FPC Ver 3.2.2
Windows 10 Pro 64-bit

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Hide Mainform and restart?
« Reply #2 on: April 23, 2015, 11:35:31 pm »
"Application.ShowMainForm := False;" in your .lpr file if it is the first run (or in your main form create),  may be. But I'm not sure to have understood fully what you mean.

But it won't help for restarting your application. If you don't mind to have very temporarily 2 instances of your program, you can start a new one and terminate the current one.

See here, for instance (windows only):
http://stackoverflow.com/questions/6020867/close-and-restart-the-current-application-in-delphi

Of course, you could use a more general "TProcess" instead of the "ShellExecute" windows API:
http://wiki.freepascal.org/Executing_External_Programs?ref=driverlayer.com/web#Run_detached_program
« Last Edit: April 23, 2015, 11:47:55 pm by ChrisF »

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Hide Mainform and restart?
« Reply #3 on: April 24, 2015, 05:43:35 pm »
In your Project1.lpr file make sure to instantiate and show your dialog:

Code: [Select]
begin
  RequireDerivedFormResource := True;
  Application.Initialize;
  Application.CreateForm(TMyDialog, MyDialog);
  MyDialog.ShowModal;
  if MyDialog.SetupOK then //custom boolean property of TMyDialog set in OK button
    // use your settings from MyDialog in the main form (or whatever)
    begin
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end;
end.
keep it simple

dietmar

  • Full Member
  • ***
  • Posts: 170
Re: Hide Mainform and restart?
« Reply #4 on: April 25, 2015, 01:50:58 am »
Thx to all!

I messed up with my code... the Out of Bound error was an other problem and had nothing to do with the startup...

A separate config app is not what I want, because:
* I have to ship and maintain a second application
* it makes things more uncomfortable for the user

The solutions you provided are working, great! I also noticed that is is _not_ necessary to restart the application, so I can ship around this problem ;)

Thx,
Dietmar
Lazarus 2.2.0RC1 with FPC 3.2.2 (32 Bit) on Windows10 (64Bit)

 

TinyPortal © 2005-2018