김영대님 홈페이쥐에 있는 네오브라우져의 북마크 기능을 표현해본건데...
그렇저렇 해결은 되었으나 역시 실력이 딸려 여기서 만족해야 될것 같네요...^^
꼭 즐겨찾기가 아니라도 업무에 따라 이러한 경우가 있을것 같아
한번 해본건데 고수님들이 한번 봐주시고요 시간이 있으시는 분은
한번 해결해보시고요 좀더 좋은 방법이 있으시면 게시판이나
zzombang@hanmail.net 으로 연락 주시면 감사하겠습니다...
미해결부분 : 하위디렉토리가 n개일때
현재는 5개까지만 해결(무식한코딩으로)...
단계별로 했으니깐 초보자가 봐도 대충은 이해가 될겁니다...
참 질문에 답변해주신분께 감사드립니다...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,FileCtrl,inifiles, Menus, Grids, Buttons, ComCtrls ;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
MainMenu1: TMainMenu;
ListBox2: TListBox;
N1: TMenuItem;
Button2: TButton;
Button3: TButton;
Button4: TButton;
StringGrid1: TStringGrid;
Button5: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure SearchDirectory(dir : string);
procedure SearchDirectory_Url(dir : string);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.SearchDirectory(dir : string);
var
Searchrec : TSearchrec;
i : integer;
st : string ; //경로조립할 문자열
begin
st := dir + '*.*';
FindFirst(st, faAnyFile, SearchRec);
i := 0;
while i = 0 do
begin
if (Searchrec.Name = '.') or (Searchrec.Name = '..') then
begin
i := FindNext(SearchRec); //다음 디렉토리, 화일을 찾음
Continue;
end;
if DirectoryExists(dir + '' + SearchRec.Name) then //찾은게 디렉토리면..
begin
st := dir + '' + Searchrec.Name;
ListBox1.Items.Add('D-'+st );
i := FindNext(Searchrec);
Continue;
end;
//찾은게 파일일 경우..
st := dir + '' + SearchRec.Name;
ListBox1.Items.Add('F-'+st);
i := FindNext(SearchRec);
end;
end;
procedure TForm1.SearchDirectory_URl(dir : string);
var
Searchrec : TSearchrec;
i : integer;
st : string ; //경로조립할 문자열
begin
st := dir + '*.*';
FindFirst(st, faAnyFile, SearchRec);
i := 0;
while i = 0 do
begin
if (Searchrec.Name = '.') or (Searchrec.Name = '..') then
begin
i := FindNext(SearchRec); //다음 디렉토리, 화일을 찾음
Continue;
end;
if DirectoryExists(dir + '' + SearchRec.Name) then //찾은게 디렉토리면..
begin
st := dir + '' + Searchrec.Name;
if LowerCase(ExtractFileExt(st)) <> '.ini' then
ListBox2.Items.Add('D-'+st );
SearchDirectory_URL(st);
i := FindNext(Searchrec);
Continue;
end;
//찾은게 파일일 경우..
st := dir + '' + SearchRec.Name;
if LowerCase(ExtractFileExt(st)) <> '.ini' then
ListBox2.Items.Add('F-'+st);
i := FindNext(SearchRec);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox1.Items.Clear;
SearchDirectory('C:WINDOWSFavorites');
end;
procedure TForm1.Button2Click(Sender: TObject);
var
dir : string;
i : Integer;
begin
ListBox2.Items.Clear;
for i := 0 to ListBox1.Items.Count - 1 do
begin
dir := ListBox1.Items.Strings[i];
if LowerCase(ExtractFileExt(dir)) = '.ini' then
Continue;
ListBox2.Items.Add(Dir);
if Copy(dir,1,1) = 'D' then
SearchDirectory_Url(Copy(Dir,3,Length(Dir)));
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
I : Integer;
Dir_name : String;
Temp_Name : String;
Directory_Level : Integer;
Check : Boolean;
begin
for i := 0 to ListBox2.Items.Count - 1 do
begin
Dir_Name := Copy(Listbox2.Items.Strings[i],3,Length(Listbox2.Items.Strings[i]));
Check := True;
Temp_Name := Dir_Name;
Directory_Level := 0;
while Check do
begin
if LowerCase(Temp_Name) = 'c:windowsfavorites' then
Check := False
else
begin
StringGrid1.cells[0,i+1] := Temp_Name;
Temp_Name := ExtractFileDir(Temp_Name);
end;
Inc(Directory_Level);
end;
with StringGrid1 do
begin
cells[1,i+1] := Dir_Name;
cells[2,i+1] := IntToStr(Directory_Level - 2);
end;
end;
StringGrid1.RowCount := i + 1;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
i : Integer;
Menu_Name : String;
Menu_Level : Integer;
MenuItem : TMenuItem;
Menu_Hint : String;
IniFile : TIniFile;
menu_1,menu_2,menu_3,menu_4,menu_5 : integer;
begin
menu_1 := -1;
menu_2 := -1;
menu_3 := -1;
menu_4 := -1;
menu_5 := -1;
with StringGrid1 do
begin
for i := 1 to RowCount - 1 do
begin
Menu_Name := ExtractFileName(cells[1,i]);
if LowerCase(ExtractFileExt(Menu_Name)) = '.url' then
begin
IniFile := TIniFile.Create(cells[1,i]);
try
Menu_Hint := IniFile.ReadString( 'InternetShortcut', 'URL', '' );
finally
IniFile.Free;
end;
MenuItem .Hint := Menu_Hint;
Menu_Name := Copy(Menu_Name,1,Length(Menu_Name) - 4);
end;
Menu_Level := StrToInt(cells[2,i]);
MenuItem := TMenuItem.Create(Self);
MenuItem.Caption := Menu_Name;
if Menu_Level = 0 then
begin
MainMenu1.Items[0].Add(MenuItem);
inc(menu_1);
menu_2 := -1;
menu_3 := -1;
menu_4 := -1;
menu_5 := -1;
end
else
begin
case Menu_Level of
1 :
begin
MainMenu1.Items[0].Items[menu_1].Add(MenuItem);
inc(menu_2);
end;
2 :
begin
MainMenu1.Items[0].Items[menu_1].Items[menu_2].Add(MenuItem);
inc(menu_3);
end;
3 :
begin
MainMenu1.Items[0].Items[menu_1].Items[menu_2].Items[menu_3].Add(MenuItem);
inc(menu_4);
end;
4 :
begin
MainMenu1.Items[0].Items[menu_1].Items[menu_2].Items[menu_3].Items[menu_4].Add(MenuItem);
inc(menu_5);
end;
5 :
begin
MainMenu1.Items[0].Items[menu_1].Items[menu_2].Items[menu_3].Items[menu_4].Items[menu_5].Add(MenuItem);
end;
end;
end;
end;
end;
end;
end.
이렇게 하면 무한으로 작동이 가능해여.
procedure TForm1.SearchDirectory(iDir : String; CurrMenu: TMenuItem);
var
iResult: Integer;
iPos: Integer;
iMenu: TMenuItem;
FindRec: TSearchRec;
begin
FindFirst(iDir + '*.*', faDirectory + faArchive, FindRec);
iResult := 0;
while iResult = 0 do
begin
Case FindRec.Attr of
faDirectory: // 폴더인 경우
begin
if (FindRec.Name <> '.') and (FindRec.Name <> '..') then
begin
iMenu := TMenuItem.Create(Self);
iMenu.Caption := FindRec.Name;
CurrMenu.add(iMenu);
SearchDirectory(iDir + '' + FindRec.Name, CurrMenu.Items[CurrMenu.Count-1]);
end;
end;
faArchive: // 파일인 경우
begin
iPos := Pos('.url', FindRec.Name);
if iPos > 0 then
begin
iMenu := TMenuItem.Create(Self);
iMenu.Caption := Copy(FindRec.Name, 1, Length(FindRec.Name)-4);
iMenu.OnClick := PopupMenuClick;
CurrMenu.Add(iMenu);
end;
end;
end;
iResult := FindNext(FindRec);
end;
end;
procedure TForm1.PopupMenuClick(Sender: TObject);
begin
ShowMessage((Sender as TMenuItem).Caption + #13 + '메뉴가 클릭되었습니다.');
end;
procedure TForm1.ToolButton1Click(Sender: TObject);
begin
SearchDirectory('C:WindowsFavorites', FavoritePopup.Items);
ToolButton1.Enabled := False;
end;