• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 501
  • Last Modified:

setting the top level viewable folder on a TDirectoryListBox

Hi,

I would like to modify Delphi 7's existing TDirectoryListBox, so that I can set a top level folder.

eg:

If I set the top level folder to be c:\games then the user can only browse the folder c:\games and below, but nothing above it or on the same level. Is this possible? I'm looking for the required code to make the modification, or some insight could be shared on what functions to override.

Thanx
0
CyberBOB6
Asked:
CyberBOB6
  • 4
  • 4
  • 3
1 Solution
 
CyberBOB6Author Commented:
maybe some more points will spart a response :(
0
 
mikelittlewoodCommented:
Where is this component from? I would need to see what properties are available for use before I could try and give you an answer   :o)
0
 
mikelittlewoodCommented:
How about using a TShellTreeView instead?
This component has a property called "Root" which you could set to "c:\games".
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
mikelittlewoodCommented:
The component is under the "Samples" tab by the way.
0
 
ZhaawZSoftware DeveloperCommented:
A simpliest way - use onChange event to check folder.

procedure TForm1.DirectoryListBox1Change(Sender: TObject);
var
  dir1 : string;
  dir2 : string;
begin
dir1 := 'd:\games\'; // allowed top directory
dir2 := DirectoryListBox1.Directory + '\'; // current directory
if not SameText(copy(dir2, 1, length(dir1)), dir1) then begin // if current directory is not within allowed top directory, then
  DirectoryListBox1.Directory := dir1; // change current directory to allowed top directory
end;
end;
0
 
CyberBOB6Author Commented:
Thanx, I have tried this method before, and while it works, it's not what I want. The user must not be able to view the folders that he cannot browse to. And thats the part I'm finding hard to implement.
0
 
ZhaawZSoftware DeveloperCommented:
Well, in this case you could create your own dirlist component from TListBox (without using TDirectoryListBox)
0
 
CyberBOB6Author Commented:
I'm not looking to re-invent the wheel here, I just want to add a feature to it. Surely there must be a way to modify its listing functions to achieve what I'm trying to do?
0
 
ZhaawZSoftware DeveloperCommented:
Well, you'll have to rewrite BuildList procedure of TDirectoryListBox and maybe some other procedures/functions too.

BuildList procedure shows directories and drive letter in TDirectoryListBox - that's why you'll have to rewrite this.
I don't know yet, how TDirectoryListBox browses directories, but I believie you'll have to rewrite this part of TDirectoryListBox too.

I think this is more difficult than writing your own component, but if you want to use customized TDirectoryListBox - good luck ;)
0
 
mikelittlewoodCommented:
Personally I would use the TShellTreeView component. I dont think you would be reinventing the wheel using it, and it has excellent directory properties .. o .. and it actually looks much more professional.
0
 
CyberBOB6Author Commented:
thanx, ended up using that component ... I didn't even know it could do all that stuff.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now