Solved

SEEKING IN FILES BIGGER THAN 2 GIG

Posted on 2006-06-23
9
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month7 days, 1 hour left to enroll

623 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