I have written a function to compare files in two listboxes against each
other. It works fine on files less than 3MB but bombs on anything over
that. I have included the function and the call to the function if anyone
can help I would really appreciate it.
See the code below
Thanks in advance
Mike Cox
zor...@acceleration.net
FUNCTION.....
function Compare(S1, S2: String): Boolean;
var
X: Integer;
FromF, ToF: file;
NumRead, NumWritten: Word;
Buf1: array[1..2048] of Char;
Buf2: array[1..2048] of Char;
begin
X := 0;
AssignFile(FromF, S1);{ Assign Source File}
Reset(FromF, 1); { Record size = 1 }
AssignFile(ToF, S2); { Assign Compare to File }
Reset(ToF, 1); { Record size = 1 }
repeat
X := X + 1;
BlockRead(FromF, Buf1, SizeOf(Buf1), NumRead);
BlockRead(ToF, Buf2, SizeOf(Buf2), NumWritten);
until (NumRead = 0) or (NumWritten <> NumRead);
if Buf1[X] <> Buf2[X] then
begin
ShowMessage(S1 + 'was not the same as ' + S2);
Form1.Memo1.Lines.Add(Buf1[X] + ' Located at position: '+
IntToStr(X) + ' ' + ' compared as ' + Buf2[X]);
Result := False;
end else
System.CloseFile(FromF);
System.CloseFile(ToF);
end;
--------------------------------------------------------------------->cut
here<----------------------------------
Here is the Call to the Function.....
procedure TForm1.Button6Click(Sender: TObject);
var
Listc, Listd, Y: Integer;
begin
if OpenDialog1.Execute then
begin
ListBox1.Items := OpenDialog1.Files;{Load the compare from ListBox}
end;
if OpenDialog2.Execute then
begin
ListBox2.Items := OpenDialog2.Files;{Load the compare to ListBox}
end;
Listc := ListBox1.Items.Count;{Get the number of items in the list box}
Listd := ListBox2.Items.Count;{Get the number of items in the list box}
{Insert Code here to check that files and positions are the same in the
listboxes}
if ListBox1.Items.Count = ListBox2.Items.Count then
begin
for Y := 0 to Listc -1 do {Run the compare function for each file}
begin
Compare( ListBox1.Items[Y] , ListBox2.Items[Y]);
end
end else
MessageDlg('Could not complete ListBoxes are not the same.', mtError,
[mbOk], 0);
end;