Solved

DriveCombo not updating on new disk

Posted on 1997-04-24
4
153 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reconfigure Delphi Install? 2 61
select query - oracle 16 100
Convert MS Word document to a PDF file 9 92
DBCtrlGrid, Delphi, Scroll 7 26
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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