راه حل اول:
function FindFirstCDROMDrive: Char;
var
drivemap, mask: DWORD;
i: Integer;
root: string;
begin
Result := #0;
root := 'A:\';
drivemap := GetLogicalDrives;
mask := 1;
for i := 1 to 32 do
begin
if (mask and drivemap) <> 0 then
if GetDriveType(PChar(root)) = DRIVE_CDROM then
begin
Result := root[1];
Break;
end;
mask := mask shl 1;
Inc(root[1]);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMEssage('First CD drive is ' + FindFirstCDROMDrive);
end;
راه حل دوم:
function getcdroms: string;
var
i: Byte;
begin
Result := '';
for i := 65 to 90 do
if GetDriveType(Char(i) + ':\') = DRIVE_CDROM then
Result := Result + Char(i);
end;
راه حل سوم:
var
ch: Char;
s: string;
begin
for ch := 'D' to 'Z' do
begin
s := ch + ':\';
if GetDriveType(PChar(s)) = DRIVE_CDROM then
ShowMessage('CDROM is ' + s[1])
end;
end;