I am working on a program designed to map a networked drive to a Linux Samba share. I have been requested to give the end users a way to select what drive they want to map. I know that some drives are off limits for use; (A:, C:, and the F:, I:, and L: drives we currently have mapped to servers elsewhere), but I'd like to be able to prevent other mapping conflicts as well. (Second CD/CDR/DVD drive, plugged in flash drives or zip drives, or even someone trying to run multiple copies of this program.)

I've tried setting every possible drive letter, then placing a TDriveComboBox component and removing anything that it mapped to, but the automated remove didn't work.

Does anyone here know of any way to do this in Delphi, or any components which can add this capacity to a program? And if so, would you please share it/them?

Thank you for your consideration.

i'm not sure if i understand well, but delphi for linux isn't Kylix?

The original program I'm writing is slated to be run on WindowsXP boxes and interface with the linux-based server boxes.

I finally found a solution to my own problem by negation...I dropped a DriveComboBox on the form, listed in my drive slot every single letter of the alphabet as a possible drive, and then had the program run through a little compare and delete loop on startup. The end result is that if a drive appears in the DriveComboBox, it doesn't appear in my select box.

How can I detect a new removable drive in the DriveComboBox after the program has been already running?

Currently I have to close then re-open the program to get the new drive updated in the
DriveComboBox.

Please help!

To determine which drives are available, their drive letters, and what kind of device they represent:

  • DWORD [b]GetLogicalDrives[/b]()
  • DWORD [b]GetLogicalDriveStrings[/b]( DWORD nBufferLength, LPTSTR lpBuffer )
  • UINT [B]GetDriveType[/B]( LPCTSTR lpRootPathName )

(Yes, the above is in C. Specify the Windows unit in your using clause to use them. Delphi will correct you about the types of the arguments as you type --chances are that the strings will be var parameters.) Either use the IDE help or Google MSDN for more information on each function.

To catch drive change notifications you need to subclass your main window. There are several ways to do this, but the simplest is just to override WndProc in one of your toplevel forms (probably the main form):

unit Unit1;
interface
uses ...
type
  TForm1 = class(TForm)
    ...
  protected
    procedure WndProc( var message: TMessage ); override;
  end;

implementation

procedure TForm1.WndProc( var message: TMessage );
  begin
  if message.msg = WM_DEVICECHANGE
    then case message.wParam of
           DBT_DEVICEARRIVAL: { A new drive is available };
           DBT_DEVICEQUERYREMOVE: { The user pressed the eject button. Allow? };
           DBT_DEVICEREMOVEPENDING: { The device is about to eject whether you like it or not. Clean up. };
           DBT_DEVICEREMOVECOMPLETE: { The device is no longer available. };
           end;
  inherited
  end;

The lParam contains a pointer to a DEV_BROADCAST_HDR record identifying the type of device. You'll have to query the system again to determine which device actually changed.

Google "msdn" and any of the above message constants for more information.

Hope this helps.


[EDIT] You know what, I just checked this and it's not quite right... Check again tomorrow evening and I'll have it working for you... :$ :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.