Recent

Author Topic: exception external SIGSEGV when trying to open a form  (Read 801 times)

billjtx

  • Newbie
  • Posts: 4
exception external SIGSEGV when trying to open a form
« on: December 12, 2025, 12:55:00 am »
I'm doing development of an engineering program I started long ago in Delphi.  It ported to Lazarus just fine a couple of years ago and I've continued developing it.  It has a large main unit with a lot of engineering calculations and 4 units/forms for data input.  I wanted to add a form to show a graph of some output, that's when I have a problem.

I added a form and that also created a unit.  I pasted in some code used from in the other forms and got various exceptions when trying to show the form via showmodal.  I started stripping the form down eventually removing a lot of the code I pasted in, still errors.  So I deleted that form and unit completely, added a completely blank form, changed the names of the form and unit and get exception SIGSEGV.  Not having much clue what the problem was I deleted that form and unit completely, added another completely blank form and unit, left all of the names at their default, still get the exception.  My other forms have a lot of stuff in them including graphing and still work fine.

When I click the button attached to this event handler I get the exception.  The other forms are reached with similar event handlers:
procedure Tcontbtest1f1.Button10Click(Sender: TObject);
begin
  form1.showmodal;
end;   

I looked in the .lpr file and it does not contain the new unit in its uses statement and does not have an application.createform for that unit.  I tried adding those and it would not compile with them added so I restored it back to its prevous state.

This is the unit in its entirety:
unit Unit1;
{$mode Delphi}
interface
uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs;
type
  TForm1 = class(TForm)
  private
  public
  end;
var
  Form1: TForm1;
implementation
{$R *.lfm}
end.

dseligo

  • Hero Member
  • *****
  • Posts: 1654
Re: exception external SIGSEGV when trying to open a form
« Reply #1 on: December 12, 2025, 06:24:13 am »
Maybe your new form isn't created.

Go to the menu Project, Project Options. Go to the 'Forms' there and check if the new form is included in list 'Auto-create forms'.

You can also create it in the code.

billjtx

  • Newbie
  • Posts: 4
Re: exception external SIGSEGV when trying to open a form
« Reply #2 on: December 12, 2025, 07:20:57 am »
Maybe your new form isn't created.
Go to the menu Project, Project Options. Go to the 'Forms' there and check if the new form is included in list 'Auto-create forms'.
You can also create it in the code.


This is correct.  The form does not show up in Project>Project Options>Forms.  I had previously discovered that it wasn't in the .lpr file but was in the .lpi file.  I don't know how or why for this behavior, I let Lazarus create the form/unit so I don't know why it wouldn't create it in all the right places.
I had assumed that it needed an entry in the .lpr file to create the form but I couldn't edit the file myself and didn't know any other way to get it in there.

So...   I change the button click event handler as below and it works without throwing an exception.

procedure Tcontbtest1f1.Button10Click(Sender: TObject);
begin
  Form1 := TForm1.Create(Self);
  form1.showmodal;
end;
« Last Edit: December 12, 2025, 07:22:35 am by billjtx »

dseligo

  • Hero Member
  • *****
  • Posts: 1654
Re: exception external SIGSEGV when trying to open a form
« Reply #3 on: December 12, 2025, 07:57:12 am »
This is correct.  The form does not show up in Project>Project Options>Forms.  I had previously discovered that it wasn't in the .lpr file but was in the .lpi file.  I don't know how or why for this behavior, I let Lazarus create the form/unit so I don't know why it wouldn't create it in all the right places.
I had assumed that it needed an entry in the .lpr file to create the form but I couldn't edit the file myself and didn't know any other way to get it in there.

Go to the menu 'Project', 'Project Inspector' and add your new form (choose pas file) there. It should be then visible in Project Options/Forms.

Quote
So...   I change the button click event handler as below and it works without throwing an exception.

procedure Tcontbtest1f1.Button10Click(Sender: TObject);
begin
  Form1 := TForm1.Create(Self);
  form1.showmodal;
end;

That way you will create new TForm1 every time you press Button1. It would be better if you create 2nd form in OnCreate or OnShow method of main form.

billjtx

  • Newbie
  • Posts: 4
Re: exception external SIGSEGV when trying to open a form
« Reply #4 on: December 13, 2025, 12:09:00 am »
I'm still a bit curious about the behavior of the IDE.  My original program was ported from Delphi and contained this directive: {$mode Delphi}.  I wondered if that could have something to do with what happened when a new form was inserted.  I did change the directives for objfpc in all of my source code and it didn't change the behavior, but I didn't do this before adding an empty form.

billjtx

  • Newbie
  • Posts: 4
Re: exception external SIGSEGV when trying to open a form
« Reply #5 on: December 13, 2025, 01:06:50 am »
Go to the menu 'Project', 'Project Inspector' and add your new form (choose pas file) there. It should be then visible in Project Options/Forms.

I checked- the new blank form showed up in project>project inspector but in project options>forms it showed up in "available forms" and not in "auto-create forms".  There is a button to move it to the auto-create list so I did that and it still threw an exception.  I go back to project options>forms and find that it doesn't persist, it moves Form1 back to the available list.  I can move it into autocreate, close that window with ok, go back into it and Form1 will be back in the available list.  There is no way to make it save, maybe it needs to make it to the .lpr file somehow.  It does already show up in the .lpi file same as the other forms.

Edit- I've been fighting with it further.  I edited the .lpr file manually and added the 2 entries to match the new blank unit.  (Then I checked options>forms and it shows the new form in the auto-create list so this implies that options>forms gets its information from the .lpr file.)  Upon trying to compile it would give me errors about multiple definitions of the new blank form name.  I did some searching with that error message text and found suggestions to use the "clean up and build" function.  I do that and afterwards the program compiles and opens the newly added form without throwing an exception.

That's a lot of time fighting with the IDE to find out that the IDE is not doing what I think it should have been doing all along (updating the .lpr file.)  I did try editing the .lpr file a few days ago but I was getting error messages I couldn't solve so I gave up on that.  Now I think I was probably not understanding what names went where.
« Last Edit: December 13, 2025, 06:15:57 am by billjtx »

dseligo

  • Hero Member
  • *****
  • Posts: 1654
Re: exception external SIGSEGV when trying to open a form
« Reply #6 on: December 14, 2025, 02:21:13 am »
That's a lot of time fighting with the IDE to find out that the IDE is not doing what I think it should have been doing all along (updating the .lpr file.)

Try to create new project, add second form and try to move this second form from "available forms" to "auto-create forms" and vice versa.
If that it is working, I don't think there is anything wrong with your Lazarus' installation.
You mentioned you started this project in Delphi. I suspect something went wrong when converting to Lazarus (or maybe original project file was malformed in some way).

dseligo

  • Hero Member
  • *****
  • Posts: 1654
Re: exception external SIGSEGV when trying to open a form
« Reply #7 on: December 14, 2025, 02:24:28 am »
My original program was ported from Delphi and contained this directive: {$mode Delphi}.  I wondered if that could have something to do with what happened when a new form was inserted.

IMHO, directive 'mode Delphi' isn't causing your problem.

 

TinyPortal © 2005-2018