Solved

SEEKING IN FILES BIGGER THAN 2 GIG

Posted on 2006-06-23
9
313 Views
Last Modified: 2010-04-04
Hello All,

I have a routine that reads in a file and as it reads the file in it writes out an index file like

index is
tdelimit_struct = record
recnum:longint;
spos:int64;
ssize:int64;
skey:array[1..10] of char;
end;

(* spos = start position in file, ssize is no of characters to read in *)

Once the data is read in a third party dll sorts the data and then supplies me back just the record no's i need for the sorted
data.

This is why the index is written as the data coming in can be delimitted or fixed field.

To read the data back in I have a tfilestream method....

seekf=tfilestream.create(ifile,fmopenread);
repeat
.
(* get record from sort , read sort key from main index then*)
.
(* and to seek a record *)
seekf.seek(delimit_struct.spos,soFromBeginning);
seekf.read(buffer,delimit_struct.ssize);

-- PROBLEM HERE ---------
The problem is when the file is over 2 gig i get a range check error on the seek - despite the fact i have a int64?

The offset crashing it was 2152430441 (which  is over 2gig).

I can seek seekf is meant to read over 2gig files?

I had similar problems with getting the size of the original files but fond code to fix this but the read is killing it?

HELP please!

This is in delphi7.

Thanks

Phil


0
Comment
Question by:PHILFRED
  • 4
  • 2
9 Comments
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16969653
Try
seekf.Position := delimit_struct.spos;
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16969781
Or use SetFilePointer win32 api function
e.g.
SetFilePointer(seekf.Handle, delimit_struct.spos, nil, FILE_BEGIN);
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16970100
Sorry the above example will not work with file >2 gb. use the following instead.

var
  MyRec : packed record L, H : cardinal end absolute i;
begin
  // your code
  SetFilePointer(fs.Handle, MyRec.L, @MyRec.H, FILE_BEGIN);
end;
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:PHILFRED
ID: 16970198
Thanks Atul - but how do i get the values into MyRec?

var
  MyRec : packed record L, H : cardinal end absolute i;
begin
  // your code
  SetFilePointer(fs.Handle, MyRec.L, @MyRec.H, FILE_BEGIN);
end;
0
 
LVL 10

Accepted Solution

by:
atul_parmar earned 125 total points
ID: 16970326
Phil, Sorry abt that!

var
  i : int64
  MyRec : packed record L, H : cardinal end absolute i;
begin
  // your code
  i := delimit_struct.spos;
  SetFilePointer(fs.Handle, MyRec.L, @MyRec.H, FILE_BEGIN);
  // because we appended the absolute to the MyRec it will point to the same location where i variable resides so will be initialized when we assign delimit_struct.spos to i (i.e. i := delimit_struct.spos;)
end

I hope, that will do. I m moving now. Happy Week end. :)

Atul.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 16970388
You can also skip the absolute mapping by using LARGE_INTEGER casting, eg:

Regards,
Russell

function GetSizeEx(Handle: THandle): Int64;
begin

  LARGE_INTEGER(result).LowPart:=GetFileSize(Handle, @LARGE_INTEGER(result).HighPart);

end;

procedure SetSizeEx(Handle: THandle; Size: Int64);
begin

  SetFilePointer(Handle, LARGE_INTEGER(Size).LowPart, @LARGE_INTEGER(Size).HighPart, FILE_END);
  Win32Check(SetEndOfFile(Handle));

end;

function SeekEx(Handle: THandle; Offset: Int64; Origin: Word): Int64;
begin

  result:=Offset;
  LARGE_INTEGER(result).LowPart:=SetFilePointer(Handle, LARGE_INTEGER(result).LowPart, @LARGE_INTEGER(result).HighPart, Origin);
  if (LARGE_INTEGER(result).LowPart = $FFFFFFFF) then RaiseLastWin32Error;

end;
0
 

Author Comment

by:PHILFRED
ID: 16970562
Ok Thanks all i will implement some code over the weekend and see what works!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now