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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 function FormatByteSize

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Boban Posted - Nov 25 2012 : 06:46:19
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;
7   L A T E S T    R E P L I E S    (Newest First)
w2m Posted - Nov 26 2012 : 10:36:51
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
Boban Posted - Nov 26 2012 : 10:27:43
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?
w2m Posted - Nov 26 2012 : 07:01:47
You must be using Delphi 7 I guess... Then use your FormatByteSize function...

William Miller
Boban Posted - Nov 26 2012 : 06:04:58
Hi William

Uses ShLwApi;

(ShLwApi.dcu) File not found.
w2m Posted - Nov 25 2012 : 17:59:18
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
Boban Posted - Nov 25 2012 : 16:32:37
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;
w2m Posted - Nov 25 2012 : 07:37:08
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