I have created a dynamic array of records which is expanded using this actionexecute method:
procedure TForm1.AddTeamActionExecute(Sender: TObject);
Var
c : integer;
begin
c := length(PrjRecArray);
PrjRecArray[c].tmpLoadPrjRec (true, 'Team', 'Big Building', '123 Main Street' ,'',
'Somewhere', 'Ohio','43210', '555-1234', 'Bob', 'Big Cheese', '555-0123', 'bob@gmail.com');
PrjSg.Cells[0,PrjSg.RowCount-1] := (PrjRecArray[c].Team);
PrjSg.Cells[1,PrjSg.rowcount-1] := (PrjRecArray[c].Name);
PrjSg.Cells[2,PrjSg.rowcount-1] := (PrjRecArray[c].addr1);
PrjSg.Cells[3,PrjSg.rowcount-1] := (PrjRecArray[c].addr2);
PrjSg.Cells[4,PrjSg.rowcount-1] := (PrjRecArray[c].city);
PrjSg.Cells[5,PrjSg.rowcount-1] := (PrjRecArray[c].state);
PrjSg.Cells[6,PrjSg.rowcount-1] := (PrjRecArray[c].zip);
PrjSg.Cells[7,PrjSg.rowcount-1] := (PrjRecArray[c].phone);
PrjSg.Cells[8,PrjSg.rowcount-1] := (PrjRecArray[c].contact);
PrjSg.Cells[9,PrjSg.rowcount-1] := (PrjRecArray[c].title);
PrjSg.Cells[10,PrjSg.rowcount-1] := (PrjRecArray[c].conPhone);
PrjSg.Cells[11,PrjSg.rowcount-1] := (PrjRecArray[c].email);
PrjSg.RowCount := PrjSg.RowCount + 1;
Revised(true);
showmessage ('PrSG Rows = ' + inttostr (PrjSg.RowCount));
c := c + 1;
SetLength (PrjRecArray, c);
showmessage ('PrjRecArray Rows = ' + inttostr (length(PrjRecArray)));
end;
The array is called PrjRecArray declared in the unit ( PrjRecArray : Array of TPrjRec;
) and is not otherwise initialized. PrjSg is a tstringgrid contained in the form and is used to display the records.
As I add more records using the AddTeamActionExecute the stringgrid continues to increase in size correctly. However, while the PrjRecordArray expands to four records correctly, the program apparently fails on the fifth iteration at the set length line. Execution hangs and never displays the second showmessage box.
Am I missing some step for using dynamic arrays properly?