You are using the wrong defined TIntegerArray. Futhermore, you are using StrToInt, which may throw errors if the input string isn't a real number.. Oh, and you forget to set the size of the result in GetNums.
Try this:
pascal Code:
unit multicalc;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
ComCtrls, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Memo1: TMemo;
Memo2: TMemo;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
procedure Button1Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
type
TStringArray = array of String;
TIntegerArray = array of Integer;
var
Form1: TForm1;
str : Array of Extended;
nums : Array of Extended;
implementation
{ TForm1 }
//took from simba, stringutil file
function Explode(del, str: string): TStringArray;
var
i,ii : integer;
lastpos : integer;
lenstr : integer;
lendel : integer;
lenres : integer;
matches : boolean;
begin;
lastpos := 1;
lenres := 0;
setlength(result,lenres);
lendel := length(del);
lenstr := length(str);
// for i := 1 to lenstr do
i := 1;
while i <= lenstr do
begin;
if not ((i + lendel - 1) > lenstr) then
begin
matches := true;
for ii := 1 to lendel do
if str[i + ii - 1] <> del[ii] then
begin
matches := false;
break;
end;
if matches then
begin;
inc(lenres);
setlength(result,lenres);
result[lenres-1] := Copy(str,lastpos,i-lastpos);
lastpos := i+lendel;
i := i + lendel-1;//Dirty
if i = lenstr then //This was the trailing delimiter
exit;
end;
end else //We cannot possibly find a delimiter anymore, thus copy the rest of the string and exit
Break;
inc(i);
end;
//Copy the rest of the string (if it's not a delimiter)
inc(lenres);
setlength(result,lenres);
result[lenres-1] := Copy(str,lastpos,lenstr - lastpos + 1);
end;
function getnums : TIntegerArray;
var
i : integer;
s : TStringArray;
begin
s:= explode(Form1.Edit1.Text, form1.memo1.text);
SetLength(result,length(s));
for i := 0 to high(s) do
result[i] := StrToIntDef(s[i],-1);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.Text := 'Numbers (In Order!) example: 0;0;0;1;2;6;76;77;77;98';
memo2.text := 'Answers';
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
arr : TIntegerArray;
begin //the error points to here
arr := getnums;
for i := 0 to high(arr) do
memo2.Lines.Add(IntToStr(arr[i]));
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
end;
initialization
{$I multicalc.lrs}
end.