Board index » delphi » Bug in filesize()

Bug in filesize()

Hi,

The function filesize's return value is casted as an integer.

How do you get the file size for files > 32k ????

Eric

 

Re:Bug in filesize()


ok, after spending $50.00 on their help line, they tell me these are indeed
bugs.  Most file i/o calls are casted with INTEGER instead of LONG INT

So forget working with files > 32k

I got no solution from them.

Can someone give me an alternative solution?  Is there a windows API to
get a file size??

Thanks

Re:Bug in filesize()


Quote
Eric Furrer wrote:

> Hi,

> The function filesize's return value is casted as an integer.

> How do you get the file size for files > 32k ????

> Eric

Eric,

Both 16 and 32 bit versions of Delphi return longints from the FileSize
function. FWIW, integers in 32 bit land are equivelent to longints.

Here is the description of FileSize:

function FileSize(var F): Longint;

Description:

The FileSize function returns the size in bytes of file F. However, if F
is a record file FileSize will return the number of records in the file.

I invite you to try the following code to prove my point:

procedure TForm1.Button1Click(Sender: TObject);
var
  f : file;
  fs : longint;
begin
  AssignFile(f, 'C:\somelargefile');
  Reset(f, 1);
  fs := FileSize(f);
  ShowMessage(IntToStr(fs));
  CloseFile(f);
end;

Joe

--
Joe C. Hecht
Borland Delphi Developer Support Group
http://www.borland.com

Re:Bug in filesize()


Quote
Eric Furrer wrote:

> ok, after spending $50.00 on their help line, they tell me these are indeed
> bugs.  Most file i/o calls are casted with INTEGER instead of LONG INT

> So forget working with files > 32k

> I got no solution from them.

> Can someone give me an alternative solution?  Is there a windows API to
> get a file size??

> Thanks

Eric,

Eric,

Both 16 and 32 bit versions of Delphi return longints from the FileSize
function. FWIW, integers in 32 bit land are equivelent to longints.

Here is the description of FileSize:

function FileSize(var F): Longint;

Description:

The FileSize function returns the size in bytes of file F. However, if F
is a record file FileSize will return the number of records in the file.

I invite you to try the following code to prove my point:

procedure TForm1.Button1Click(Sender: TObject);
var
  f : file;
  fs : longint;
begin
  AssignFile(f, 'C:\somelargefile');
  Reset(f, 1);
  fs := FileSize(f);
  ShowMessage(IntToStr(fs));
  CloseFile(f);
end;

While we do not guarentee an answer, I would be very suprised
if you received a confirmation that this was a bug. The FileSize
functions have been used in the pascal line of products for years,
and have proven to be very reliable.

Joe
--
Joe C. Hecht
Borland Delphi Developer Support Group
http://www.borland.com

Re:Bug in filesize()


Quote
>   fur...@mjw.com (Eric Furrer) writes:
>  ok, after spending $50.00 on their help line, they tell me these are indeed
>  bugs.  Most file i/o calls are casted with INTEGER instead of LONG INT

>  So forget working with files > 32k
>  Can someone give me an alternative solution?  Is there a windows API to
>  get a file size??

I copied this from the online help and tried it
var
   f: file of Byte;
   size : Longint;
   S: string;
   y: integer;
 begin
   if OpenDialog1.Execute then begin
     AssignFile(f, OpenDialog1.FileName);
     Reset(f);
     size := FileSize(f);
     S := 'File size in bytes: ' + IntToStr(size);
     edit1.text := s;
     CloseFile(f);
   end;

And tested on a file that was 197632 bytes in size.

No problem. I am using Delphi 2.01

johan

Re:Bug in filesize()


Sundial Services <i...@sundialservices.com> wrote in article > Three
observations:

Quote

> (1)        Please do not report a "serious bug confirmed" if you simply don't
know
> why your code does not work.  One thing to ask yourself is, "would
500,000
> copies of this product have been sold if I'm the first one to have
encountered
> this?"  Please understand that I do not mean this as a slam to you.  When
you
> encounter a genuine bug, which is extremely rare, you will know it.

> (2)        To Borland:  What we have here is a seriously frustrated, seriously
pissed
> off user.  One of the best ways that Borland can further strengthen its
> already-strengthening position in the marketplace is by finding creative
ways
> to eliminate the $X-a-minute-wait frustration.

> (3)        To everyone:  Notice how neither this user, nor any of the rest of
us,
> actually needed to spend the bucks to get the answer.  The answer was
> broadcasted right here.  Now THAT is Internet efficiency.

> Another observation:  surf to "support.novell.com" sometime for an
exemplary
> demonstration of how the Internet -can- be used to provide customer
support.  
> If you've encountered something you can go right there and search their
> problem database on-line.  You can download patches and updated software.
> It's infinitely more efficient than a phone-call.

> THIS is what Borland should be replicating, as quickly as possible.  The
> effect of frustration and anger in a computer (developer!) customer
cannot be
> underestimated.  Granted, software vendors are wrestling with the load as
much
> as their users are, but this is something that .. well, if Borland spent
$2
> million on it, it would pay back the effort spent.

I absolutely 100% agree with you! I am delighted to see Joe Hecht and
others from Borland showing an interest in solving problems on the
Internet. I hope that this has become some sort of official Borland policy
and receiving the full support of the company.

I generally stash their answers into a help file for later reference, even
if I don't need the information immediately. It is becomming sort of a
home-made FAQ that I find myself using more and more often.

Cheers to you and the Borland people, Doug Lurie.

Re:Bug in filesize()


Quote
Randolph D. Lurie wrote:

> Sundial Services <i...@sundialservices.com> wrote in article > Three
> observations:

> > (1)   Please do not report a "serious bug confirmed" if you simply don't> know> > why your code does not work.  One thing to ask yourself is, "would> 500,000> > copies of this product have been sold if I'm the first one to have> encountered

What does quantity have to do with it?

I asked myself the same question when I hit a bug in D2 and it was
a legit bug.

Quantity does not make quality....windows is proof of that in itself.

--
Windows feeds my body.  Linux feeds my soul.
All opinions expressed are mine.

Re:Bug in filesize()


On 27 Feb 1997 16:13:19 GMT, fur...@mjw.com (Eric Furrer) wrote:

Quote
>How do you get the file size for files > 32k ????

Hi Eric,

in 32-Bit environments an integer is handled like a longint. It's
working - I tried it.

c'ya
Michael

Re:Bug in filesize()


Stefan Paetow (remove * to mail me) <*del...@jhbpop01.iafrica.com> wrote in
article <331d5d21.60126...@jhb-news.iafrica.com>...

Quote
> On 28 Feb 97 16:13:21 GMT, "Randolph D. Lurie" <dlu...@net1plus.com>
wrote:

> >home-made FAQ that I find myself using more and more often.

> >Cheers to you and the Borland people, Doug Lurie.

> Doug, would it be possible if you made this FAQ available? Even for a
small
> cost?

Stefan, it looks like I put my foot in my mouth up to my hip :-). At this
point the FAQ is a long way from being very useful to anyone else, since it
was never intended for anyone but me. However, I will see what I can do to
straighten it out and try to post it somewhere. Please don't expect this to
happen for several months, since there would be a lot of work to do.

Cheers, Doug Lurie

Other Threads