I am running into an Access violation exception when running my application and I am running out of ideas on how to resolve it. This application when complete will be open sourced, so I have no problems sharing any of the source you see under the GPL license.
Basically, it is a
Gopher client, yes, that very outdated Internet protocol. However, it is a great way to learn and understand a new language. If you read my introduction, you will notice that I come from Python, but have used Pascal in 2001ish. I am trying to get back into Pascal, as I am seeing it as a powerful compiled language to have alongside my existing Python knowledge. So, here is the code which I am having issue with at the moment:
{$mode objfpc}{$H+}
TGopherMenu = record
gtype: char;
name: String;
selector: String;
host: String;
port: Integer;
end;
AGopherMenu = Array of TGopherMenu;
.... SNIP ....
function TGopherClient.GetMenu(const selector: String): AGopherMenu;
var
data: TMemoryStream;
entry: TStringList;
i: Integer;
begin
SetLength(Result, 1);
data:=SendSelector(selector); { Returns back a TMemoryStream with data from remote gopher server. }
entry:=TStringList.Create;
Repeat
GetEntry(data, entry); { entry becomes a TStringList using the Delimiter feature on data, which is a single line. }
WriteLn('Got Entry back: ',entry.Count);
i:=Length(Result)+1;
SetLength(Result, i);
WriteLn('set length=',Length(Result));
Result[i].gtype:=entry.Strings[0][1];
WriteLn('Got gtype: ',Result[i].gtype);
WriteLn('entry.Strings[0]=',Length(entry.Strings[0]));
Result[i].name:=entry.Strings[0]; { On the 8th iteration this fails with an Access violation, see output below.. }
WriteLn('Past.');
Result[i].selector:=entry.Strings[1];
Result[i].host:=entry.Strings[2];
Result[i].port:=StrToInt(entry.Strings[3]);
WriteLn(entry.Strings[0]);
WriteLn(data.Position,',',data.Size);
until (data.Position>=data.Size);
WriteLn('Are we here?');
entry.Free;
end;
If you need additional code, or the entire program, I do plan on uploading this onto my BitBucket page soon, and can point you to that. All those WriteLns were added in various efforts to troubleshoot this. For some reason setting Result
.name causes this exception.
Output follow:
Got Entry back: 4
set length=2
Got gtype: i
entry.Strings[0]=27
Past.
iWelcome to my Gopherspace!
43,1739
Got Entry back: 4
set length=3
Got gtype: i
entry.Strings[0]=60
Past.
i***********************************************************
119,1739
Got Entry back: 4
set length=4
Got gtype: i
entry.Strings[0]=60
Past.
i** CELEBRATING GOPHER'S 25 YEAR ANNIVERSARY! **
195,1739
Got Entry back: 4
set length=5
Got gtype: i
entry.Strings[0]=60
Past.
i** Plain text is beautiful! **
271,1739
Got Entry back: 4
set length=6
Got gtype: i
entry.Strings[0]=60
Past.
i***********************************************************
347,1739
Got Entry back: 4
set length=7
Got gtype: i
entry.Strings[0]=60
Past.
i** What's new? - Updated on Jan. 25, 2016 **
423,1739
Got Entry back: 4
set length=8
Got gtype: i
entry.Strings[0]=60
Past.
i** **
499,1739
Got Entry back: 4
set length=9
Got gtype: i
entry.Strings[0]=60
Past.
TApplication.HandleException Access violation
Stack trace:
$00000000004C7C0A
$00000000005020BA line 45 of main.pas
$00000000004EB299 line 1023 of include/customform.inc
$00000000004EA38A line 629 of include/customform.inc
$00000000004D0941
$00000000006C6841 line 5341 of include/wincontrol.inc
$00000000004EC528 line 1443 of include/customform.inc
$00000000006D450D line 1451 of include/control.inc
$00000000006C3C0A line 4300 of include/wincontrol.inc
$00000000006C3B30 line 4350 of include/wincontrol.inc
$00000000004F0640 line 2682 of include/customform.inc
$00000000006C2158 line 3556 of include/wincontrol.inc
$00000000006E0EDA line 5460 of include/control.inc
$00000000006DD228 line 4300 of include/control.inc
$00000000004E9EF2 line 486 of include/customform.inc
$00000000004EEF52 line 2196 of include/customform.inc
$00000000004FB90D line 1387 of include/application.inc
Segmentation fault (core dumped)
Any ideas on why this would be happening? Am I using an Array correctly here? I recenrly heard a plea from the small/tiny gopher community that Firefox is removing a critical feature needed for OverbiteFF to continue functioning, meaning that Gopher will no longer be supported in Firefox even with an add-on, so this native Gopher client will really help that community out if I can get it working. Many thanks.
Oh, the gopher server this is hitting, in case you want to check out the data is gopher://gopher.veroneau.net/