Solved

DriveCombo not updating on new disk

Posted on 1997-04-24
4
148 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Fantastic!

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

Thanks for the solution. Points well earned.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi OLE Error 8 82
Mydac connection data base issue 3 106
Convert Jpg /PNG To GIF 5 101
LAN or WAN ? 11 58
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now