事實證明,系統單元使用的內部查找程序也由於使用低容量數字類型而出現問題。我編寫了我自己的調用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;
14 gb您必須考慮使用數據庫來代替。 – RRUZ 2011-05-18 21:46:14
也有流訪問文件。但我不記得他們是否支持> 2GB的文件。 – CodesInChaos 2011-05-18 21:52:50
Streams支持超過十年的大文件,@Code。參見'TStream',它的兩個僞抽象實現'Seek'。 – 2011-05-18 22:03:18