Mega Code Archive

 
Categories / Delphi / Examples
 

Which kind of drive

Title: Which kind of drive Question: Use the windows API standard call GetDriveType(). The function takes a PChar a parameter and returns a TDriveType. Say you have a Form (Form1) with two Edit controls on it (Edit1 and Edit2). and a Answer: procedure TForm1.Button1Click(Sender: TObject); var s : String; begin s:=edit1.Text; setlength(s,1); if GetDriveType(Pchar(s)) DRIVE_REMOTE then edit1.Text:=Volumeid(s[1]) else edit1.Text:=NetworkVolume(s[1]); S:=S+#58+#92; Setlength(s,3); case GetDriveType(Pchar(s)) of 0: edit2.Text:='drive type cannot be determined.'; 1 : edit2.Text:='root directory does not exist.'; DRIVE_REMOVABLE: edit2.Text:='drive can be removed from the drive.'; DRIVE_FIXED: edit2.Text:='disk cannot be removed from the drive.'; DRIVE_REMOTE: edit2.Text:='drive is a remote (network) drive.'; DRIVE_CDROM: edit2.Text:='drive is a CD-ROM drive.'; DRIVE_RAMDISK: edit2.Text:='drive is a RAM disk.'; end; end;