本文所述Delphi實(shí)例用以獲取指定的磁盤空間容量大小,檢測(cè)磁盤大小,從combox中選擇磁盤代號(hào)等功能。點(diǎn)擊“檢測(cè)驅(qū)動(dòng)器”容量信息的按鈕,就可以在下邊顯示出該磁盤的總空間大小以及要用容量的大小。讀者可根據(jù)需求添加對(duì)應(yīng)的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);//要顯示的驅(qū)動(dòng)器名 GetDiskFreeSpace(driver, sec1, byt1, cl1, cl2); cl1 := cl1*sec1 * byt1; cl2 := cl2*sec1 * byt1; Label1.Caption:= '該驅(qū)動(dòng)器總共容量' + Formatfloat('###,##0',cl2) + '字節(jié)'; Label2.Caption := '該驅(qū)動(dòng)器可用容量' + Formatfloat('###,##0',cl1) + '字節(jié)';end;end.
|
新聞熱點(diǎn)
疑難解答
圖片精選