ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 function FormatByteSize
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Boban

Yugoslavia
41 Posts

Posted - Nov 25 2012 :  06:46:19  Show Profile  Reply
Hi

How to call this function with OpenImageEnDialog component to show me the label caption?

function FormatByteSize(const bytes: Longint): string;
const
B = 1; //byte
KB = 1024 * B; //kilobyte
MB = 1024 * KB; //megabyte
GB = 1024 * MB; //gigabyte
begin
if bytes > GB then
result := FormatFloat('#.## GB', bytes / GB)
else
if bytes > MB then
result := FormatFloat('#.## MB', bytes / MB)
else
if bytes > KB then
result := FormatFloat('#.## KB', bytes / KB)
else
result := FormatFloat('#.## bytes', bytes) ;
end;

w2m

USA
1990 Posts

Posted - Nov 25 2012 :  07:37:08  Show Profile  Reply
I don't think it is possible to do with OpenImageEnDialog.

My EBook has a chapter on using the OpenPictureDialog to provide a label with bytesize file information and provides a OpenPictureDialog component that does this as well. The memorysize and the filesize is displayed as a number expressed as a size value in bytes, kilobytes, megabytes, or gigabytes, depending on the size.


265.82 KB

William Miller
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

Boban

Yugoslavia
41 Posts

Posted - Nov 25 2012 :  16:32:37  Show Profile  Reply
Hi William

It suits me and OpenDialog but the error is in my label1.Caption: = 'File size:' + FormatByteSize (bytes);
What do I need to change or add to this code?
---------------------------------------------------------------
function FormatByteSize(const bytes: Longint): string;
const
B = 1; //byte
KB = 1024 * B; //kilobyte
MB = 1024 * KB; //megabyte
GB = 1024 * MB; //gigabyte
begin
if bytes > GB then
result := FormatFloat('#.## GB', bytes / GB)
else
if bytes > MB then
result := FormatFloat('#.## MB', bytes / MB)
else
if bytes > KB then
result := FormatFloat('#.## KB', bytes / KB)
else
result := FormatFloat('#.## bytes', bytes) ;
end;


procedure TForm1.ToolButton4Click(Sender: TObject);
var
OpenDlg: TOpenDialog;
begin
OpenDlg := TOpenDialog.Create (nil);
OpenDlg.Filter := OPEN_MEDIA_FILES_EXTENDED;
OpenDlg.Options := [ofAllowMultiSelect];
if OpenDlg.Execute then begin

Label1.Caption := 'File Size: ' + // Here's the problem;

end;
OpenDlg.Free;
end;
Go to Top of Page

w2m

USA
1990 Posts

Posted - Nov 25 2012 :  17:59:18  Show Profile  Reply
function FormatByteSize(Bytes: Int64): string;
//Converts a numeric value into a string that represents the number expressed as a size value in bytes, kilobytes, megabytes, or gigabytes, depending on the size
var
  iSize: array[0..255] of WideChar;
begin
  Result := '';
  // same formating used in statusbar of Explorer
  Result := ShLwApi.StrFormatByteSizeW(Bytes, iSize, Length(iSize) - 1);
end;

uses ShLwApi, hyieutils;

procedure TForm1.Button1Click(Sender: TObject);
var
 iOpenDialog: TOpenDialog;
 iFilename: string;
 iFileSize: integer // bytes
begin
 iOpenDialog := TOpenDialog.Create(self);
 try
   iOpenDialog.Filter := OPEN_MEDIA_FILES_EXTENDED;
   if iOpenDialog.Execute then 
   begin
     iFilename := iOpenDialog.Filename;
     // get the filesize
     iFileSize := IEGetFileSize(iFilename)
     Label1.Caption := 'File Size: ' + FormatByteSize(iFileSize); 
   end;
  finally
    iOpenDialog.Free;
  end;
end;

This would be pointless for multi-selected files, because only the last multi-selected file name would appear in the Label, so I removed OpenDlg.Options := [ofAllowMultiSelect];

William Miller
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

Boban

Yugoslavia
41 Posts

Posted - Nov 26 2012 :  06:04:58  Show Profile  Reply
Hi William

Uses ShLwApi;

(ShLwApi.dcu) File not found.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Nov 26 2012 :  07:01:47  Show Profile  Reply
You must be using Delphi 7 I guess... Then use your FormatByteSize function...

William Miller
Go to Top of Page

Boban

Yugoslavia
41 Posts

Posted - Nov 26 2012 :  10:27:43  Show Profile  Reply
Hi William

Thank You

You are right I use Delphi7 and I anticipated, or until it is either a problem or an operating system is to use the Windows XP Professional Service Pack 3, but not to him. I have Delphi 2010, but I never used it
Does he have the ability to do this and whether the finished application must be installed Net.Framework or other files on another computer applications that would work?
Go to Top of Page

w2m

USA
1990 Posts

Posted - Nov 26 2012 :  10:36:51  Show Profile  Reply
I do not understand what you are trying to say, but Delphi 2010 is very good and does not require use of Net.Framework. Delphi 2010 is the version that I am using. It will take you awhile to understand unicode, but other than that, development with Delphi 2010 is just like Delphi 7.

William Miller
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: