The Delphi example described in this article is used to obtain the specified disk space capacity, detect the disk size, select the disk code from the combox, and other functions. Click the "Check Drive" capacity information button, and the total space of the disk and the amount of capacity to be used will be displayed below. Readers can add corresponding Button and label controls according to their needs.
The main program code is as follows:
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);//To display The drive name GetDiskFreeSpace(driver, sec1, byt1, cl1, cl2); cl1 := cl1*sec1 * byt1; cl2 := cl2*sec1 * byt1; Label1.Caption:= 'Total capacity of the drive' + Formatfloat('###,##0',cl2) + 'byte'; Label2.Caption := 'Available capacity of the drive' + Formatfloat('###,##0',cl1) + 'Bytes';end;end.