现成的例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
//检测结果
Result:Integer;
//驱动器根目录
Driver:String;
begin
Driver:=Edit1.text;
//检测驱动器类型
Result:=GetDriveType(pchar(Driver));
Case Result of
Drive_Removable:Memo1.Lines.Add(Edit1.text+'为可移动驱动器');
Drive_Fixed:Memo1.Lines.Add(Edit1.text+'不可移动驱动器');
Drive_Remote:Memo1.Lines.Add(Edit1.text+'网络驱动器');
Drive_CDROM:Memo1.Lines.Add(Edit1.text+'CD-ROM驱动器');
Drive_RamDisk:Memo1.Lines.Add(Edit1.text+'虚拟驱动器');
Else Memo1.Lines.Add(Edit1.text+'驱动器符号无效');
end;
end;
end.