![]() |
|
Removable Drive Listesi Alma - Baskı Önizleme +- Delphi Can (https://www.delphican.com) +-- Forum: Delphi (https://www.delphican.com/forumdisplay.php?fid=3) +--- Forum: İpuçları (https://www.delphican.com/forumdisplay.php?fid=24) +--- Konu Başlığı: Removable Drive Listesi Alma (/showthread.php?tid=2885) |
Removable Drive Listesi Alma - mcuyan - 11-11-2018 Merhaba Arkadaşlar. Çıkarılabilir USB disklerin listesini almak için: procedure GetDriveLetters(AList: TStrings); var vDrivesSize: Cardinal; vDrives: array [0 .. 128] of Char; vDrive: PChar; typ: Integer;//** s: string;//** begin AList.BeginUpdate; try AList.Clear; vDrivesSize := GetLogicalDriveStrings(SizeOf(vDrives), vDrives); if vDrivesSize = 0 then Exit; vDrive := vDrives; while vDrive^ <> #0 do begin s := StrPas(vDrive); //** typ := GetDriveType(PChar(s));//** if typ <> 0 then//** case typ of//** DRIVE_REMOVABLE://** begin//** AList.Add(StrPas(vDrive)); end;//** end;//** Inc(vDrive, SizeOf(vDrive)); end; finally AList.EndUpdate; end; end; Kullanımı: GetDriveLetters(ListBox1.Items); Not: //** kısmıını silerseniz tüm Sürücü listesini alabilirsiniz.. Cvp: Removable Drive Listesi Alma - SercanTEK - 13-11-2018 Kodu aşağıdaki gibi düzenlersek comboboxtan seçilen sürücülerin listesi alınır. Denemek için Forma 1 er adet Combobox,Listbox ve button koymanız yeterlidir. unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
const
DRIVE_UNKNOWN = 0;
DRIVE_NO_ROOT_DIR = 1;
DRIVE_REMOVABLE = 2;
DRIVE_FIXED = 3;
DRIVE_REMOTE = 4;
DRIVE_CDROM = 5;
DRIVE_RAMDISK = 6;
DRIVE_ALL = 7;
implementation
{$R *.dfm}
procedure SurucuListesi(AList: TStrings; AType: integer);
var
vDrivesSize: Cardinal;
vDrives: array [0 .. 128] of Char;
vDrive: PChar;
typ: Integer;
s: string;
begin
AList.BeginUpdate;
try
AList.Clear;
vDrivesSize := GetLogicalDriveStrings(SizeOf(vDrives), vDrives);
if vDrivesSize = 0 then
Exit;
vDrive := vDrives;
while vDrive^ <> #0 do
begin
if AType <> DRIVE_ALL then
begin
s := StrPas(vDrive);
typ := GetDriveType(PChar(s));
if typ <> 0 then
if typ = AType then
AList.Add(StrPas(vDrive));
end
else
AList.Add(StrPas(vDrive));
Inc(vDrive, SizeOf(vDrive));
end;
finally
AList.EndUpdate;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SurucuListesi(ListBox1.Items, combobox1.ItemIndex);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with Combobox1.items do
begin
Clear;
Add('DRIVE_UNKNOWN');
Add('DRIVE_NO_ROOT_DIR');
Add('DRIVE_REMOVABLE');
Add('DRIVE_FIXED');
Add('DRIVE_REMOTE');
Add('DRIVE_CDROM');
Add('DRIVE_RAMDISK');
Add('DRIVE_ALL');
end;
Combobox1.ItemIndex := 7 ;
Combobox1.Style := csDropDownList;
end;
end.
Removable Drive Listesi Alma - mcuyan - 13-11-2018 Elinize sağlık.. |