Exceptions when minimizing application lazarus / 13-General ---------------------------------------------------------------------- wht244 · 2009-09-13 11:50 this is the code: Form1 (frmMain) Code: [Select]unit mainfrm; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,   mysql40conn, mysql41conn, mysql50conn, sqlite3conn, sqldb, IniFiles, DbCtrls,   DBGrids, StdCtrls, ExtCtrls, ComCtrls, Buttons, ActnList, db; type   { TfrmMain }   TfrmMain = class(TForm)     aZmienHaslo: TAction;     aMWSzukaj: TAction;     aMWEdytuj: TAction;     aMWImport: TAction;     aMWStan: TAction;     aMWSprzedaj: TAction;     aMWDodaj: TAction;     aPracownicy: TAction;     aInformacje: TAction;     aWyloguj: TAction;     aZakoncz: TAction;     alMain: TActionList;     aprMain: TApplicationProperties;     BitBtn1: TBitBtn;     BitBtn2: TBitBtn;     BitBtn3: TBitBtn;     BitBtn4: TBitBtn;     BitBtn5: TBitBtn;     BitBtn6: TBitBtn;     Button1: TButton;     Button2: TButton;     Button3: TButton;     Button4: TButton;     ds: TDatasource;     dsMagazyn: TDatasource;     dsZlecenia: TDatasource;     dsSprzedaz: TDatasource;     DBGrid1: TDBGrid;     DBGrid2: TDBGrid;     DBGrid3: TDBGrid;     Label2: TLabel;     Label3: TLabel;     Label4: TLabel;     mysql40: TMySQL40Connection;     mysql41: TMySQL41Connection;     mysql50: TMySQL50Connection;     Panel1: TPanel;     Panel2: TPanel;     Panel3: TPanel;     Panel4: TPanel;     Panel5: TPanel;     Panel6: TPanel;     Panel7: TPanel;     Panel8: TPanel;     Panel9: TPanel;     Splitter2: TSplitter;     Splitter3: TSplitter;     sqlite3: TSQLite3Connection;     sql: TSQLQuery;     sqlMagazyn: TSQLQuery;     sqlSprzedaz: TSQLQuery;     sqlZlecenia: TSQLQuery;     sqlt: TSQLTransaction;     sb: TStatusBar;     procedure FormCreate(Sender: TObject);   private     { private declarations }   public     function ShowOptionsDlg: integer;   end; var   frmMain: TfrmMain; implementation { TfrmMain } uses   ustawieniafrm; function TfrmMain.ShowOptionsDlg: integer; begin   Result := 0;   frmUstawienia := TfrmUstawienia.Create(Application);   if frmUstawienia.ShowModal = mrOk then   begin   end   else Result := -1;   frmUstawienia.Free; end; procedure TfrmMain.FormCreate(Sender: TObject); var   ini: TIniFile; begin   ini := TIniFile.Create('cfg.ini');   if ini.ReadInteger('DBConnection', 'DBType', -1) = -1 then   begin     if ShowOptionsDlg < 0 then     begin       ini.Free;       Application.ShowMainForm := false;       Application.Terminate;       Exit;     end;   end;   ini.Free; end; initialization   {$I mainfrm.lrs} end. Form2 (frmUstawienia)Code: [Select]unit ustawieniafrm; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,   ComCtrls, ExtCtrls, StdCtrls, EditBtn, Spin; type   { TfrmUstawienia }   TfrmUstawienia = class(TForm)     btnOk: TButton;     btnAnuluj: TButton;     btnUstawBaze: TButton;     cbTyp: TComboBox;     edtMySQL: TEdit;     edtMySQLNazwa: TEdit;     edtMySQLUser: TEdit;     edtMySQLHaslo: TEdit;     edtSQLite: TFileNameEdit;     gbxSQLite: TGroupBox;     gbxMySQL: TGroupBox;     Label1: TLabel;     Label2: TLabel;     Label3: TLabel;     Label4: TLabel;     Label7: TLabel;     Label8: TLabel;     Label9: TLabel;     PageControl1: TPageControl;     Panel1: TPanel;     edtMySQLPort: TSpinEdit;     tshBaza: TTabSheet;   private     { private declarations }   public   end; var   frmUstawienia: TfrmUstawienia; implementation { TfrmUstawienia } uses   mainfrm; initialization   {$I ustawieniafrm.lrs} end. And the problem is: when i execute the ShowModal function of frmUstawienia, then, when minimizing, i get an exception like "Project svc.exe raised exception class 'External: SIGSEGV'. What's going on? ---------------------------------------------------------------------- wht244 · 2009-09-18 10:06 nobody knows anything? it's a serious problem, because i shouldn't create many forms when starting application. they should be created by other procedures... ---------------------------------------------------------------------- DelphiFreak · 2009-09-18 11:09 Hi, did not really analyse your problem, but I see one common mistake in your code. First advice: In unit remove the global Variable: var   frmUstawienia: TfrmUstawienia; and copy this into your method . Second advice: Change frmUstawienia := TfrmUstawienia.Create(Application); to frmUstawienia := TfrmUstawienia.Create(nil); and place a try-finally statement there. Example: function TfrmMain.ShowOptionsDlg: integer; var frmUstawienia: TfrmUstawienia; begin   result:=-1;   frmUstawienia := TfrmUstawienia.Create(nil);   try     if frmUstawienia.ShowModal <> mrOk then exit;     //dosomething     result:=0;   finally     frmUstawienia.free;   end; end; ---------------------------------------------------------------------- wht244 · 2009-09-18 11:19 Quote from: DelphiFreak on September 18, 2009, 01:09:50 pmFirst advice: In unit remove the global Variable: var   frmUstawienia: TfrmUstawienia; and copy this into your method . i always leave this variable, because it is automatically generated in delphi and lazarus. Quote from: DelphiFreak on September 18, 2009, 01:09:50 pmSecond advice: Change frmUstawienia := TfrmUstawienia.Create(Application); to frmUstawienia := TfrmUstawienia.Create(nil); and place a try-finally statement there. Example: function TfrmMain.ShowOptionsDlg: integer; var frmUstawienia: TfrmUstawienia; begin   result:=-1;   frmUstawienia := TfrmUstawienia.Create(nil);   try     if frmUstawienia.ShowModal <> mrOk then exit;     //dosomething     result:=0;   finally     frmUstawienia.free;   end; end; i created this code only to demonstrate, that application is encountering an exception, when procedure OnCreate of Form1 (frmMain) is trying to create Form2 (frmUstawienia) and that second form's ShowModal function is called, then application is minimized. i think try..finally statement won't protect me from that exception, because it will be encountered always when i try to minimize... ---------------------------------------------------------------------- eny · 2009-09-18 15:51 Not reproducible with WinXP + lazarus 0.9.27-21258. Works without raising an exception (although I would follow the advice of DF). ---------------------------------------------------------------------- wht244 · 2009-09-19 10:57 //edit: in lazarus 0.9.26.2 almost everythink ok... btw: i've been using laz 0.9.29 from snapshots