Recent

Author Topic: Child unit runs immediately when I test program  (Read 1958 times)

nikel

  • Full Member
  • ***
  • Posts: 186
Child unit runs immediately when I test program
« on: March 24, 2018, 10:32:51 pm »
Hello, I have a main form in my project. I added one more form (settings form for my program) and another one for advanced settings. I mean the hierarchy is:

Unit1 (Form1) > settings_unit (settings_frm) > advanced_protection_settings (advanced_protection_settings_frm)

When I run my program using Lazarus, it shows the dialog I defined in advanced_protection settings. Here's the code:

Code: Pascal  [Select][+][-]
  1. procedure Tadvanced_protection_settings_frm.FormCreate(Sender: TObject);
  2. begin
  3.   ShowMessage(IntToStr(CalculateProtTotal()));
  4. end;    

I tried removing "uses" clause for the unit and ShowModal statement in main form but I got the same problem. Can anyone help me? Sorry for my English.

Regards.

bigeno

  • Sr. Member
  • ****
  • Posts: 266
Re: Child unit runs immediately when I test program
« Reply #1 on: March 24, 2018, 10:38:01 pm »
When you have autocreate forms then they will auto create all at start

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Child unit runs immediately when I test program
« Reply #2 on: March 24, 2018, 10:45:24 pm »
Remove those forms from autocreated forms (in Project Options->Forms) or do the same directly in *.lpr file.

Or simply change their property Visible to False. They'll be autocreated, but invisible until you Show (ShowModal) them.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

nikel

  • Full Member
  • ***
  • Posts: 186
Re: Child unit runs immediately when I test program
« Reply #3 on: March 24, 2018, 10:55:36 pm »
I'm happy that I got quick replies. If I remove them from Project Options > Forms, my program can't open second form. I get error:

Project x raised exception class 'External SIGSEGV'.

In file 'unit1.pas' at line 94:
settings_frm.ShowModal;

EDIT: I've come across with changing visibility idea but I don't want to do such a dirty fix.
« Last Edit: March 24, 2018, 11:00:35 pm by nikel »

bigeno

  • Sr. Member
  • ****
  • Posts: 266
Re: Child unit runs immediately when I test program
« Reply #4 on: March 24, 2018, 11:00:34 pm »
if not autocreate forms then you need create them.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Form2:=TForm2.Create(Nil);  //Form2 is created
  4.   Form2.ShowModal;            //Form2 is displayed
  5.   FreeAndNil(Form2);          //Free Form2
  6. end
http://wiki.freepascal.org/Form_Tutorial

nikel

  • Full Member
  • ***
  • Posts: 186
Re: Child unit runs immediately when I test program
« Reply #5 on: March 24, 2018, 11:13:44 pm »
Wow that helped a lot. Thanks.

 

TinyPortal © 2005-2018