Solved

DriveCombo not updating on new disk

Posted on 1997-04-24
4
151 Views
Last Modified: 2010-04-04
Using the TDriveComboBox, i am scanning disks and cataloging the information. Delphi 2, Win95.
Problem is:
When I change the CD-rom, the drive combo box does not update to reflect the new volume label, which i use to identify the CD in my database. The combobox still has the volume label of the previous CD-rom displayed.
I have tried the update and invalidate methods, to no avail.

I would really apreciate a solution to this one.
If it's quite involved, I will require sample code, as i am at a complete loss.

Thanks,
       Ash. (Fooman)
0
Comment
Question by:Fooman
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
sperling earned 100 total points
ID: 1335710
Just install this unit, and you'll have TChangeAwareDriveComboBox

Regards,

Erik.



unit ChangeAwareDCB;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, FileCtrl;

type
  TChangeAwareDriveComboBox = class(TDriveComboBox)
  private
  protected
    function  HookWndProc (var message : TMessage) : BOOLEAN;
  public
    constructor Create (AOwner : TComponent); override;
    destructor Destroy; override;
  published
  end;

procedure Register;

implementation
const
  DBT_DEVICEARRIVAL            = $8000;
  DBT_DEVICEREMOVECOMPLETE     = $8004;

procedure Register;
begin
  RegisterComponents('Samples', [TChangeAwareDriveComboBox]);
end;


constructor TChangeAwareDriveComboBox.Create (AOwner : TComponent);
begin
  inherited Create(AOwner);
  // Hooking main window, as controls never receive WM_DEVICECHANGE
  Application.HookMainWindow(HookWndProc);
end;

destructor TChangeAwareDriveComboBox.Destroy;
begin
  // Cleaning up after ourselves
  Application.UnhookMainWindow(HookWndProc);
  inherited Destroy;
end;

function TChangeAwareDriveComboBox.HookWndProc (var message : TMessage) : BOOLEAN;
var
  OldDrive   : CHAR;
  OldCursor  : TCursor;
  OldEnabled : BOOLEAN;                                    
begin
  if ( message.msg = WM_DEVICECHANGE )
  and ( (message.wParam = DBT_DEVICEARRIVAL)
     or (message.wParam = DBT_DEVICEREMOVECOMPLETE)
    )
  then begin
    // Device has changed, either arrived or completely removed
    // Don't bother to check for drive type, therefore this
    // will get called e.g. whenever a network drive is
    // added/removed

    // Saving state
    OldDrive := Drive;
    OldCursor := Cursor;
    OldEnabled := Enabled;

    // Don't wan't anyone to change state... Just in case...
    Enabled := FALSE;
    // This takes a second or two
    Cursor := crHourglass;

    // Calling inherited method for building the drive list
    BuildList;

    // Restoring state
    Drive := OldDrive;
    Cursor := OldCursor;
    Enabled := OldEnabled;
  end;
end;

end.

0
 

Author Comment

by:Fooman
ID: 1335711
Hi Erik,

   Sorry for not grading your answer quickly, I had to try it out...
I compiled the code into a component, but when i use it, the app just hangs. no IDE error, just hangs. The window is still grayed, (hasn't initialised?).

As it happens, I have recieved a solution from a ng, just change the textcase property, and it rebuilds it's list! (odd!)

But, if you can explain the hang, i'll certainly award the points, you've earned them.

Also: now my taskbar is only about 10 pixels high, and therefore useless. this happened after recompiling the component lib, but I don't know if it has anything to do with your code. (unlikely).

Thanks for your efforts, and again, if you can explain the error, I will give you the points.
Ash.
0
 
LVL 3

Expert Comment

by:sperling
ID: 1335712
Ooops...

Add

Result := FALSE;

as the last line of this function, just before the end statement.

function TChangeAwareDriveComboBox.HookWndProc (var message : TMessage) : BOOLEAN;


Sorry...

The return value from this function indicates to Delphi whether you've handled the message or normal processing should continue. As I didn't set any return value, it would be random what the function returned... Not good.


Regards,

Erik.
0
 

Author Comment

by:Fooman
ID: 1335713
Fantastic!

Added the Result:= True;
and the component works perfectly.

Thanks for the solution. Points well earned.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question