Access Violation problem...

Posted by Jason on February 16, 2005

Hi all...

My problem is this...The following code is used to get the most popular 4-digit number from a database of lottery drawn 4-digit numbers. It works fine except when I go to close the application it gives me an Access Violation error.

function FourDigitFrequency(Conn:TADOConnection;Query:TADOQuery):integer; export;
var
i,num,final : integer;
myarray : array[0000..9999] of integer;

begin
final := 0;
for i := 0000 to 9999 do
begin
myarray[i] := 0;
end;
Conn.LoginPrompt := false;
Conn.Open;
Query.Close;
Query.SQL.Text := 'Select * From Numbers Where Threedigit = '+chr(39)+'Null'+chr(39);
Query.Open;
with Query do
begin
First;
while not eof do
begin
num := StrToInt(Query.FieldByName('Fourdigit').AsString);
myarray[num] := myarray[num]+1;
Next;
end;
end;
num := 0;
for i := 0000 to 9999 do
begin
if num < myarray[i] then
begin
num := myarray[i];
end;
end;
for i := 0000 to 9999 do
begin
if myarray[i] = num then
begin
final := i;
end;
end;
Result := final;
end;

Related Articles and Replies



Reply

Name:
E-Mail:

Subject:

Comments:


[ Delphi Tutorials -- by DelphiLand ]