32B CRC for files.

I need a function that returns 32b CRC values for a specified file.  It seems like a simple issue but I just can't seem to work around it.  I've tried several bits of my own code and a couple components.  None seem to work either reliably or without pointer errors.  Basically I have a list of files and paths (200+) in a multidimensional array and I need to generate Hex CRC's for each of them and add them to the array as string values.  Something simple like this:

function GetCRC32(PathFile : String) : string;
var

begin
  { Code to calc Hex CRC }
  Result := {Hexvalue as String};
end;

for CtrA := 0 to Pred(Path2.Count) do
  for CtrB := 0 to Pred(File2.Count) do
    Array[CtrA,CtrB,5] := GetCRC32((Path2[CtrA] + File2[Ctr[B]));
LlysanderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

duendeCommented:
Const
  crc_polynomial = $EDB88320;
  crc32_value  : Integer = $FFFFFFFF;

Var
  crc_table: Array[0..255] of Integer;

Procedure Build_CRC_Table;
Var
  x, y : Integer;
  CRC_Value: Integer;

begin
  for x := 0 to 255 do
  begin
    crc_value := x;
    for y := 1 to 8 do
      if (crc_value and 1 = 1) then
        crc_value := (crc_value shr 1) xor crc_polynomial
      else
        crc_value := crc_value shr 1;
    crc_table[ x ] := crc_value;
  end;
end;

function GetCRC32(PathFile : String) : string;
var
  f   : TFileStream;
  crc : Integer;
  cnt : Integer;
  Value : Byte;
begin
  { Code to calc Hex CRC }
  Result := '';
  if FileExists(PathFile) then
  Begin
    f := TFileStream.Create(PathFile, fmOpenRead or fmShareDenyNone);
    f.Seek(0,0);
    crc := crc32_value;
    for cnt := 0 to f.Size-1 do
    Begin
      f.Read(Value,1);
      crc := crc_table[Byte(crc xor LongInt(value))] xor ((crc shr 8) and $00ffffff);
    end;
    f.Free;
    crc := crc xor crc32_value;
    Result := Format('%x',[crc]);
  end;
end;


Procedure test;
begin
Build_crc_table;  
for CtrA := 0 to Pred(Path2.Count) do
  for CtrB := 0 to Pred(File2.Count) do
    Array[CtrA,CtrB,5] := GetCRC32((Path2[CtrA] + File2[Ctr[B]));


end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LlysanderAuthor Commented:
A little slow but the fix works correctly.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.