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?
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.