Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TDirectoryOutline

Status
Not open for further replies.

jbpelletier

Programmer
Sep 8, 2001
232
CA
Hi,

im not able to find how i can set a TDirectoryOutline object to be initialize (in code) to a specific path value.
In fact im able but the component dont show the proper expand (visualy its incorect)

DirectoryOutline1.Directory:=path; //will set the correct value
but i keep the old visual expand (previously clcked by user)

tanx

jb
 
I fibnaly found something in the help files / exemple. After minor modification, this do what i was looking for.

in the code , DirLstBox is my TDirectoryOutline

procedure TFrmOpenFolder.ExpandToDir(const Dest: string);
var
TempPath, NextDir: TFileName;
SlashPos: Integer;
TempItem: Longint;

function GetChildNamed(const Name: string): Longint;
begin
DirLstBox.Items[TempItem].Expanded := True;
Result := DirLstBox.Items[TempItem].GetFirstChild;
while Result <> InvalidIndex do
begin
if DirLstBox.Items[Result].Text = Name then Exit;
Result := DirLstBox.Items[TempItem].GetNextChild(Result);
end;
end;

begin
TempItem := 1; { start at root }
TempPath := UpperCase(Dest); //the component is set to upper case too
if Pos(':', TempPath) > 0 then
TempPath := Copy(TempPath, Pos(':', TempPath) + 1, Length(TempPath));
if TempPath[1] = '\' then System.Delete(TempPath, 1, 1);
NextDir := TempPath;
while Length(TempPath) > 0 do
begin
SlashPos := AnsiPos('\', TempPath);
if SlashPos > 0 then
begin
NextDir := Copy(TempPath, 1, SlashPos - 1);
TempPath := Copy(TempPath, SlashPos + 1, Length(TempPath));
end
else
begin
NextDir := TempPath;
TempPath := '';
end;
TempItem := GetChildNamed(NextDir);
end;
DirLstBox.SelectedItem := TempItem;
end;

jb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top