[SOLVED] Exception class 'External: SIGSEGV' lazarus / 12-Debugger ---------------------------------------------------------------------- Adri · 2019-04-27 21:48 All, Upon compiling a simple program I get a message: Project project1 raised exception class 'External: SIGSEGV'. In file 'unit1.pas' at line 47: Memo1Lines.LoadFromFile(aFileName); The code is simple enough, see below. What I try to do is to show the contents of a simple text file, which does exist on my system. The form has nothing more then a button and a memo object. Apparently it goes wrong upon displaying the file content in the memo object; with line 47 marked as comment the application does run. Can anyone tell me what I am doing wrong?  Should I better use a ListBox instead? I also think the code after 'except' can be done in a better way. Any suggestions? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; type  { TForm1 }  TForm1 = class(TForm)  Memo1   : TMemo;  btnClose: TEdit;  procedure btnCloseClick(Sender: TObject);   private    { private declarations }  public    { public declarations }   end; var  Form1: TForm1;  Memo1: TMemo; implementation{$R *.lfm} Procedure ProcessFile(aFileName:String);  var    MyFile      : Text;    Line      : String;    Counter, i  : Integer;    myStringList: TStringList;  begin    try      AssignFile(MyFile,aFileName);      {$I-}        Reset(MyFile);      {$I+}      If (IoResult = 0) Then      Begin      Counter:=1;        myStringList:=TStringList.Create;               //Create my StringList        Memo1.Lines.LoadFromFile(aFileName);      myStringList.LoadFromFile(aFileName);        for i := 0 to Memo1.Lines.Count-1 do          Memo1.Lines[i] := IntToStr(i) + ' ' + Memo1.Lines[i];        Inc(Counter);      end;      myStringList.Free;    except      on E: EInOutError do       writeln('File handling error occurred. Details: ', E.Message);    end;    CloseFile(MyFile)  end; { TForm1 } procedure TForm1.btnCloseClick(Sender: TObject);begin  Close;end; begin  ProcessFile('D:\TestFile.txt');end. ---------------------------------------------------------------------- lainz · 2019-04-27 22:17 That's because "ProcessFile" is not a method of your form, then can't find Memo1. Another problem is you're calling ProcessFile outside the Form as well, better call it OnCreate event. And finally you'r code seems too complex, I reduced it. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; type  { TForm1 }  TForm1 = class(TForm)    btnClose: TEdit;  Memo1   : TMemo;  procedure btnCloseClick(Sender: TObject);  procedure FormCreate(Sender: TObject);   private    { private declarations }  procedure ProcessFile(aFileName: string);  public    { public declarations }   end; var  Form1: TForm1; implementation{$R *.lfm} Procedure TForm1.ProcessFile(aFileName:String);begin  Memo1.Lines.LoadFromFile(aFileName);end; { TForm1 } procedure TForm1.btnCloseClick(Sender: TObject);begin  Close;end; procedure TForm1.FormCreate(Sender: TObject);begin  ProcessFile('D:\TestFile.txt');end; end. I think you can extend it adding if FileExists(aFileName) then... else ShowMessage('File does not exists') ---------------------------------------------------------------------- lucamar · 2019-04-28 00:32 In fact, you're doing quite a lot of thngs wrong ... or "almost wrong" (which is a recipe for disaster). This is closer to your code than Lainz's and more correct (or at least a little bit cleaner) than yours: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; type  { TForm1 }  TForm1 = class(TForm)  Memo1   : TMemo;  btnClose: TEdit;  procedure FormCreate(Sender: TObject);  procedure btnCloseClick(Sender: TObject);   private    { private declarations }    procedure ProcessFile(aFileName:String);  public    { public declarations }   end; var  Form1: TForm1;  Memo1: TMemo; implementation {$R *.lfm} uses LazFileUtils; { TForm1 } procedure TForm1.ProcessFile(aFileName:String);var  {MyFile was used only to test if the file was readable;          replaced by a call to FileIsReadable()}  {Line was never used: deleted}  {Counter was used for nothing: deleted}  i  : Integer;  {myStringList was used for... nothing: deleted}begin  if FileIsReadable(aFileName) then  try    Memo1.Lines.LoadFromFile(aFileName);    for i := 0 to Memo1.Lines.Count-1 do      Memo1.Lines[i] := IntToStr(i) + ' ' + Memo1.Lines[i];  except    on E: EInOutError do      {writeln can't be safely used in a GUI app; replaced by ShowMessage}      ShowMessage('File handling error occurred. Details: ' + E.Message);  end;end; procedure TForm1.FormCreate(Sender: TObject);begin  ProcessFile('D:\TestFile.txt');end; procedure TForm1.btnCloseClick(Sender: TObject);begin  Close;end; end. ---------------------------------------------------------------------- Adri · 2019-04-28 06:52 Guys (?), you’re great, many thanks for explaining and improving.  Some ‘extra’ lines where there for future use, not implemented yet, but with your improvements as base I can continue (and sleep better). This amateur can continue! Thanks again.