Re: [Lazarus] Problem growing an array
On 25/1/13 6:38, appjaws wrote: On 25/01/13 18:26, Howard Page-Clark wrote: On 25/1/13 3:55, appjaws wrote: Hi, Could one of you experts look at my code please. My program crashes after the first set of strings are added because -- I think -- the length is not updating. You're not initialising the array of array correctly. Try this: if Length(collection) < (y+1)then begin SetLength(collection, y+1); SetLength(information[0],y+1); SetLength(information[1],y+1); SetLength(information[2],y+1); SetLength(information[3],y+1); SetLength(information[4],y+1); SetLength(information[5],y+1); SetLength(information[6],y+1); SetLength(information[7],y+1); end; -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Problem growing an array
On 25/01/13 18:26, Howard Page-Clark wrote: On 25/1/13 3:55, appjaws wrote: Hi, Could one of you experts look at my code please. My program crashes after the first set of strings are added because -- I think -- the length is not updating. The following is just a snipet. It's hard to tell from a snippet, but I don't see anywhere that you are initialising the values of your array indices x and y. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus Thank you for your reply, procedure TForm1.MenuItemInputClick(Sender: TObject); //initial setup begin SetLength(collection,1); SetLength(information,8,1); x := 0; y := 0; end; Sorry I missed that out. Paul -- ---This message has been sent using Thunderbird on kubuntu--- -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Problem growing an array
On 25/1/13 3:55, appjaws wrote: Hi, Could one of you experts look at my code please. My program crashes after the first set of strings are added because -- I think -- the length is not updating. The following is just a snipet. It's hard to tell from a snippet, but I don't see anywhere that you are initialising the values of your array indices x and y. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] Problem growing an array
Hi, Could one of you experts look at my code please. My program crashes after the first set of strings are added because -- I think -- the length is not updating. The following is just a snipet. type Detail = record Extra1, Extra2, Extra3, Extra4, Extra5, Extra6, Extra7, Extra8 :string end; var Form1: TForm1; head : array [0..7] of string = ('Extra1', 'Extra2', 'Extra3', 'Extra4','Extra5', 'Extra6', 'Extra7', 'Extra8'); x : integer; y : integer; z : integer; w : integer; currentLength : integer; collection : array of Detail; information : array of array of string; procedure TForm1.MenuItemInputClick(Sender: TObject); //initial setup begin SetLength(collection,1); SetLength(information,8,1); end; procedure TForm1.ButtonNextClick(Sender: TObject); begin // extend array lengths if Length(collection) < (y+1)then begin SetLength(collection, y+1); SetLength(information[x],y+1); end; // load array information[0,y] := TEdit1.Text; information[1,y] := TEdit2.Text; information[2,y] := TEdit3.Text; information[3,y] := TEdit4.Text; information[4,y] := TEdit5.Text; information[5,y] := TEdit6.Text; information[6,y] := TEdit7.Text; information[7,y] := TEdit8.Text; //display aray lenghts z := (Length(collection)); LabelResult.Caption := inttostr(z); w := (Length(information)); LabelResult1.Caption := inttostr(w); //write to listbox for x := 0 to 7 do begin ListBox1.Items.Add(head[x] + ' ' + information[x,y] + ' '); end; //clear edit boxes TEdit1.Text := ' '; TEdit2.Text := ' '; TEdit3.Text := ' '; TEdit4.Text := ' '; TEdit5.Text := ' '; TEdit6.Text := ' '; TEdit7.Text := ' '; TEdit8.Text := ' '; y := y + 1 end; After the first set of strings are added, I get this error message:- Project protection raised exception class 'External: SIGSEGV'. I'm sure it's just me not understanding how arrays should be manipulated, Look forward to any help Paul -- ---This message has been sent using Thunderbird on kubuntu--- -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus