The Delphi example described in this paper is used to obtain the specified disk space capacity, detect the disk size, and select the disk code from the Combox. By clicking on the "Detect drive" Capacity information button, you can display the total space size of the disk and the size of the capacity to be used below. The reader can add corresponding button and label controls as needed.
The main program code looks like this:
Unit Unit1;
Interface
uses
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)//drive name to display
getdiskfreespace (driver, SEC1, BYT1, CL1, Cl2);
CL1: = CL1*SEC1 * BYT1;
Cl2: = CL2*SEC1 * BYT1;
Label1.caption:= ' The total capacity of the drive ' + formatfloat (' ###,# #0 ', Cl2) + ' byte ';
Label2.Caption: = ' The drive usable capacity ' + formatfloat (' ###,# #0 ', CL1) + ' byte ';
End;
End.