Solved

DriveCombo not updating on new disk

Posted on 1997-04-24
4
154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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