Access violation error when executing TDataSet's Next method

218 Views Asked by At

When looking to move the pointer on to the next record, an error message is shown that says:

Access violation at address 004070E2 in module 'main_p.exe'. Write of address 00000000

Any way of resolving this?

var
  i: integer;
begin
  with dmData.dmEventInfo do
  begin
    tblEventinfo.Open;
    i := 0;
    while NOT tblEventinfo.Eof do
    begin
      arrNames[i] := tblEventinfo['bandname'];
      tblEventinfo.Next;
      i := i + 1;
    end;

  end;
end;
1

There are 1 best solutions below

0
Ilyes On BEST ANSWER

You don't show the declaration of the arrNames array , but I think the problem was in the Length.

var
  i: integer;  arrNames : array of string;
begin
    SetLength(arrNames , tblEventinfo.RecordCount);
    i := 0;
    while NOT tblEventinfo.Eof do
    begin
      arrNames[i] := tblEventinfobandname.Value;
      tblEventinfo.Next;
      Inc(I);
    end;

  end;