Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DriveCombo not updating on new disk

Posted on 1997-04-24
4
Medium Priority
?
158 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

610 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