事实证明,系统单元使用的内部查找例程也由于使用了低容量数字类型而存在问题。我编写了自己对 Windows SetFilePointerEx() 函数的调用,一切正常。我在下面提供了源代码,以防它可能对其他人有所帮助。我已经包含了我创建的代码以正确获取记录数,因为您将需要两者。其他一切都一样。
// Some constants
const
kernel = 'kernel32.dll';
function SetFilePointerEx(hFile: Integer; distanceToMove: Int64; var newFilePointer: Int64; moveMethod: DWORD): boolean; stdcall; external kernel name 'SetFilePointerEx';
// easyGetFileSize() is a replacement filesize function. Use it to get the number of bytes in the huge file. To get the number of records just "div" it by the record size.
function GetFileSizeEx(hFile: THandle; var FileSize: Int64): BOOL; stdcall; external 'kernel32.dll' name 'GetFileSizeEx';
function easyGetFileSize(theFileHandle: THandle): Int64;
begin
if not GetFileSizeEx(theFileHandle, Result) then
RaiseLastOSError;
end;
// ---- Replacement seek function. Use this instead.
procedure mySeek(var f: File; recordSize, recNum: Int64);
var
offsetInBytes, numBytesRead: Int64;
pBigInt: ^Int64;
begin
offsetInBytes := recNum * recordSize;
pBigInt := nil; // Not interested in receiving a new pointer after seek.
// Call the Windows seek call since Delphi 6 has problems with huge files.
if not SetFilePointerEx(TFileRec(f).Handle, offsetInBytes, pBigInt^, FILE_BEGIN) then
raise Exception.Create(
'(mySeek) Seek to record number # '
+ IntToStr(recNum)
+ ' failed');
end;