Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit to FileSize function

Status
Not open for further replies.

Balchy

Programmer
Apr 8, 2003
3
0
0
CA
It appears there is a limit to the FileSize function in Delphi 6. The function returns a 4 byte integer that reports incorrect file sizes for very large files (e.g. on DVDs). Has this changed in Delphi 7 (say Filesize:integer, to Filesize:Int64)?
 
The Size function in the TStream (and hence TFileStream) class returns an Int64 in Delphi 7. It returns a LongInt (31 bit signed integer) in Delphi 5. I haven't got Delphi 6.

Andrew



 
Thanks towerbase. Delphi 6 has Tstream and hence TFileStream. The following code worked on a 3.3 Gbyte file.

function BigFileSize(Filename:string):Int64;
var
BigFileStream : TFileStream;
begin
BigFileStream := TFileStream.Create(Filename, fmOpenRead);
BigFileSize := BigFileStream.Size;
BigFileStream.Free;
end;

Now I'm tracing back my Integers and replacing with Int64.
Thanks again,
Balchy
 
I'm surprised your BigFileSize function worked because it doesn't seem to be returning a value in result. It's also considered good practice to use try..finally constructs when allocating resources.

Code:
function BigFileSize(FileName: string): Int64;
begin
  with TFileStream.Create(FileName,fmOpenRead) do try
    result := Size;
  finally
    free;
  end;
end;

 
Balchy's function is returning a value. You can return a value from a function by assigning a value to the function itself i.e.
Code:
  BigFileSize := BigFileStream.Size;
is equivalent to:
Code:
  Result := BigFileStream.Size;
But the preferred method is to use "Result". Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Quite right, Clive. I'm so used to assigning to result I forgot about the original Pascal way of returning values.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top