Lazarus

Using the Lazarus IDE => Editor => Topic started by: CarmichaelJohn on July 14, 2020, 01:00:55 am

Title: Main Form will not call a new form with ShowModal
Post by: CarmichaelJohn on July 14, 2020, 01:00:55 am
Hello,
If I am in the wrong forum to ask this please excuse me.
I am having difficulty in getting the main unit/form in my program
to call another form using ShowModal. I have placed the new form’s
name in the uses clause of the main form.  Yet the program will
successfully execute and the main form shows up.  Then when I
click on the menu item for the new form I get an error message:
“Project project (my project’s name) raised exception class
‘External:SVGSEGV’.  The called form is called ‘Form9', and the
call statement looks as follows:
“procedure TForm1.MenuItem11Click(Sender: TObject);
begin
  //
  Form9.ShowModal;
  //
end;“

I built the program several days ago and then went back to it to add
this new form.  Is there a formal “Add to Program” or “Add to Project”
that I am missing, or is there something else that I must do to have
the main form recognize Form9.
Thank you in advance for any help you might provide,
John
Title: Re: Main Form will not call a new form with ShowModal
Post by: RAW on July 14, 2020, 01:25:14 am
Try this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormClick(Sender: TObject);
  2. begin
  3.   Form9:= TForm9.Create(Self);
  4.   Form9.SetBounds(0,0,Width,Height);
  5.   Form9.ShowModal;
  6. end;

Or maybe better like this ...  :)

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormClick(Sender: TObject);
  2. begin
  3.   Form2 := TForm2.Create(nil);
  4.   try
  5.     Form2.SetBounds(0, 0, Width, Height);
  6.     Form2.ShowModal;
  7.   finally
  8.     Form2.Release;
  9.     Form2 := nil;
  10.   end;
  11. end;
Title: Re: Main Form will not call a new form with ShowModal
Post by: Blaazen on July 14, 2020, 01:25:26 am
@  I have placed the new form’s name in the uses clause of the main form.

Actually, there must be name of the unit where the form is defined.

But SIGSEGV indicates that Form9 is not created. Look at the *.lpr file of your project. There must be something like this:
Code: Pascal  [Select][+][-]
  1. Application.CreateForm(TForm9, Form9);

Also, that form must be Visible:=False; (set it in Object Inspector).
Title: Re: Main Form will not call a new form with ShowModal
Post by: CarmichaelJohn on July 14, 2020, 02:22:51 am
Blaazen and Raw,
Thank you both so much for this information.  Now I know and will be able to avoid this problem in the future.  I very much appreciate you're taking the time and effort to help me.
John
TinyPortal © 2005-2018