TechTricks
Technical answers from the trenches 
 
 
 
 

     
   
Making TDirectoryListBox Easier for End Users
 
   
 Posted: 4 December 2000
 
   
 
 Applies to: All Versions
 
   
 
Audience: Intermediate
 
       
   

Introduction

While currently relegated to the Win3.x tab of the Delphi component palette, TDirectoryListBox can be a very useful tool for file-browsing utilities.

As written though, the tDirectoryListBox component doesn't select (open) a directory until you double-click it. We've received reports from several users that find that confusing.

While tDirectoryListBox provides an openCurrent method, you can't simply call this from the component's OnClick event handler, for doing so disables much of the built-in keyboard support.

The following outlines a reasonable compromise:

  1. In an appropriate place, declare a boolean variable to serve as a flag.

  2. In OnClick, set the flag to True.

  3. In OnChange, check the flag. If it's TRUE, call openCurrent and then reset the flag to FALSE.

  4. The following shows this in action:

    procedure TForm1.DirectoryListBox1MouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
    
       // set flag to make it easier for the user
       blnOpenCurrent := TRUE;
    
    end;
    
    procedure TForm1.DirectoryListBox1Click(Sender: TObject);
    begin
    
       if blnOpenCurrent then  # actually triggered by the mouse
       begin
          directoryListBox1.openCurrent;
          blnOpenCurrent := FALSE;
       end;
    
    end;
    
    

    Please note that in the above sample, blnOpenCurrent is declared as a private member variable of Form1, meaning it's declared in the form's private section.

    A demonstration sample is available in our Download section. While designed for a different article, it includes this trick.

 

       

Top

Feedback About Paradox Delphi Assorted Web Stuff
 
 
Copyright © 2000-2004, techtricks.com; All Rights Reserved.
Acknowledgements, Disclaimers, Terms and Conditions.
Article last updated on 31 May 2003

 

Other Sites: Paradox, Delphi, Perl, Web Stuff, and More


 

[- End -]