本文所述Delphi實例用以獲取指定的磁盤空間容量大小,檢測磁盤大小,從combox中選擇磁盤代號等功能。點擊“檢測驅動器”容量信息的按鈕,就可以在下邊顯示出該磁盤的總空間大小以及要用容量的大小。讀者可根據需求添加對應的Button與label控件。
主要程序代碼如下所示:
unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; Label1: TLabel; Label2: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);var driver:pchar; sec1, byt1, cl1, cl2:longword;begin driver:=pchar(edit1.text);//要顯示的驅動器名 GetDiskFreeSpace(driver, sec1, byt1, cl1, cl2); cl1 := cl1*sec1 * byt1; cl2 := cl2*sec1 * byt1; Label1.Caption:= '該驅動器總共容量' + Formatfloat('###,##0',cl2) + '字節'; Label2.Caption := '該驅動器可用容量' + Formatfloat('###,##0',cl1) + '字節';end;end.
新聞熱點
疑難解答
圖片精選