xpher
asked on
File Size
How can I find the file size of an image file and display the size in say a Label Caption?
I am using a FileListBox to click on to Open the File.
Using Delphi4.
Have tried the function in the help section but hangs up when trying to open a file previously opened.
I am using a FileListBox to click on to Open the File.
Using Delphi4.
Have tried the function in the help section but hangs up when trying to open a file previously opened.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Madshi it works great. Only problem now is to try and understand it.
I think my original problem was that I was naive enough to think that clicking on another file would automatically close down the other. I'll have to investigate how to close the image before opening another.
Thanks again
Chris:))
ps Happy New Year
I think my original problem was that I was naive enough to think that clicking on another file would automatically close down the other. I'll have to investigate how to close the image before opening another.
Thanks again
Chris:))
ps Happy New Year
Happy new year... :-)
Hmm. How do you open the image files? Perhaps I can then tell you how to close them again...
Regards, Madshi.
Hmm. How do you open the image files? Perhaps I can then tell you how to close them again...
Regards, Madshi.
ASKER
Hi Madshi
Thanks for comment.
I open the image files by clicking on the file name in the file list box.
procedure TForm1.FileListBox1Click(S ender: TObject);
begin
Image1.Picture.LoadFromFil e(FileList Box1.Filen ame);
end;
This all works fine until I try the function for file size shown in Delphi help as mentioned earlier.
Many thanks for helping. Look forward to a reply.
Regards
Chris :))
Thanks for comment.
I open the image files by clicking on the file name in the file list box.
procedure TForm1.FileListBox1Click(S
begin
Image1.Picture.LoadFromFil
end;
This all works fine until I try the function for file size shown in Delphi help as mentioned earlier.
Many thanks for helping. Look forward to a reply.
Regards
Chris :))
Hi Chris,
hmmm. I don't understand it. Here's the source from Delphi4, that is called when you call Image1.Picture.LoadFromFil e. It should be the same code with Delphi2/3:
procedure TGraphic.LoadFromFile(cons t Filename: string);
var
Stream: TStream;
begin
Stream := TFileStream.Create(Filenam e, fmOpenRead or fmShareDenyWrite);
try
LoadFromStream(Stream);
finally
Stream.Free;
end;
end;
So with "Stream.Free" the file is properly closed again. So I really don't understand why you've had problems with the other filesize function.
Could you please (1) tell me the name of the other function and (2) try to call it before loading the image? Does it work, then?
Regards, Madshi.
hmmm. I don't understand it. Here's the source from Delphi4, that is called when you call Image1.Picture.LoadFromFil
procedure TGraphic.LoadFromFile(cons
var
Stream: TStream;
begin
Stream := TFileStream.Create(Filenam
try
LoadFromStream(Stream);
finally
Stream.Free;
end;
end;
So with "Stream.Free" the file is properly closed again. So I really don't understand why you've had problems with the other filesize function.
Could you please (1) tell me the name of the other function and (2) try to call it before loading the image? Does it work, then?
Regards, Madshi.
ASKER
Hi Madshi
Thanks for comment.
I open the image files by clicking on the file name in the file list box.
procedure TForm1.FileListBox1Click(S ender: TObject);
begin
Image1.Picture.LoadFromFil e(FileList Box1.Filen ame);
end;
This all works fine until I try the function for file size shown in Delphi help as mentioned earlier.
Many thanks for helping. Look forward to a reply.
Regards
Chris :))
Thanks for comment.
I open the image files by clicking on the file name in the file list box.
procedure TForm1.FileListBox1Click(S
begin
Image1.Picture.LoadFromFil
end;
This all works fine until I try the function for file size shown in Delphi help as mentioned earlier.
Many thanks for helping. Look forward to a reply.
Regards
Chris :))
ASKER
Hi Madshi
Thanks for comment.
I open the image files by clicking on the file name in the file list box.
procedure TForm1.FileListBox1Click(S ender: TObject);
begin
Image1.Picture.LoadFromFil e(FileList Box1.Filen ame);
end;
This all works fine until I try the function for file size shown in Delphi help as mentioned earlier.
Many thanks for helping. Look forward to a reply.
Regards
Chris :))
Thanks for comment.
I open the image files by clicking on the file name in the file list box.
procedure TForm1.FileListBox1Click(S
begin
Image1.Picture.LoadFromFil
end;
This all works fine until I try the function for file size shown in Delphi help as mentioned earlier.
Many thanks for helping. Look forward to a reply.
Regards
Chris :))
Hmmm. Are you stuttering? :-)
ASKER
oops! don't know what happened seems to have posted comments again sorry. ignore last two.
In response to your last comment, the function name I was trying to use was FileSize. In the help section it gives FileSize, Seek, FilePos Example. I had tried butchering this to just use file size. I've now tried again and realised that I forgot the last line to close the file.
This is what I have ended up with (from D4 help) and it works now placing FileSize into a Label Caption:
procedure TForm1.FileListClick(Sende r: TObject);
var
f: file of Byte;
size : Longint;
S: string;
begin
AssignFile(f, FileList.FileName);
Reset(f);
size := FileSize(f);
S := 'File size in bytes: ' + IntToStr(size);
Seek(f,size div 2);
CloseFile(f);
begin
Image1.Picture.LoadFromFil e(FIleList .Filename) ;
Label1.Caption := s;
end;
end;
Many thanks for all your help and getting me to think. Hope to communicate again.
Cheers
Chris :-))
In response to your last comment, the function name I was trying to use was FileSize. In the help section it gives FileSize, Seek, FilePos Example. I had tried butchering this to just use file size. I've now tried again and realised that I forgot the last line to close the file.
This is what I have ended up with (from D4 help) and it works now placing FileSize into a Label Caption:
procedure TForm1.FileListClick(Sende
var
f: file of Byte;
size : Longint;
S: string;
begin
AssignFile(f, FileList.FileName);
Reset(f);
size := FileSize(f);
S := 'File size in bytes: ' + IntToStr(size);
Seek(f,size div 2);
CloseFile(f);
begin
Image1.Picture.LoadFromFil
Label1.Caption := s;
end;
end;
Many thanks for all your help and getting me to think. Hope to communicate again.
Cheers
Chris :-))
:-)
See you...
Regards, Madshi.
See you...
Regards, Madshi.
ASKER