I'm trying to clear a stringgrid but I'm getting an inconsistent access violation message which seems to appear after the last column has been cleared. Here is the code:
procedure ClearTable;
var
i:integer;
begin
for i := 0 to 3 do
begin
frmHighscores.HighscoreTable.Cols[i].Clear;
end;
end;
And here is the procedure that calls it:
procedure TfrmHighscores.sortbtnClick(Sender: TObject);
var
SortedScores :array of Thighscore;
i: integer;
Ascending:boolean;
begin
ClearTable;
Case sortRGP.ItemIndex of
0: Ascending := False;
1: Ascending :=True;
end;
AssignFile(HighScoreFile, 'HighScoreFile.DAT');
Reset(HighScoreFile);
If Filesize(Highscorefile) <= 1 then
begin
showmessage('There arent enough items to sort!');
end;
If Filesize(Highscorefile) > 1 then
begin
SetLength(SortedScores, Filesize(Highscorefile)-1);
i:=0;
While not eof(HighScoreFile) do
begin
Read(Highscorefile, Highscore[i+1]);
sortedScores[i].Name := Highscore[i+1].Name;
sortedScores[i].Score := Highscore[i+1].Score;
sortedScores[i].DateSet := Highscore[i+1].DateSet;
sortedScores[i].Difficulty := Highscore[i+1].Difficulty;
inc(i);
end;
Closefile(highscorefile);
Quicksort(SortedScores, Low(SortedScores), High(SortedScores)+1, Ascending);
end;
end;
The error message when i try to run it is
Project C:\Users\Owner\V0.66\Project1.exe faulted with message: 'access
violation at 0x00401c51: write of address 0x00316572'. Process Stopped. Use Step or Run
to continue.
The error goes away when I change the code to this:
procedure ClearTable;
var
i:integer;
begin
for i := 0 to 3 do
begin
showmessage('Attempting to clear Col ' +inttostr(i));
frmHighscores.HighscoreTable.Cols[i].Clear;
showmessage('Col ' +inttostr(i) + ' cleared successfully');
end;
end;