Fejl i mappeGennemLøb
Er der nogen der kan sige mig hvad der er galt med denne del af en kode til et pgr.Det er ikke så meget resultatet af gennemløbet men hvorfor den fejler (Error msg) under gennemløb. ??
KODE:
unit MappeGennemLobU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, Menus, ShellAPi, Buttons, StdCtrls, IniFiles, Registry,
ComCtrls, ShlObj, ActiveX, ComObj, ActnList, ToolWin;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Memo1: TMemo;
procedure StartSearch;
procedure Button1Click(Sender: TObject);
procedure SearchForFiles( path: string; var Value: TStringList; rec:Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
html,htmStr,style,sti,Titel,BGColor,FontName,Acolor,Ahover,linkStyle,GemAndring : string;
AntalX, AntalIKat, taller, fixed, totCount,FontSize,ColCount : integer;
arrText : array of string;
arrTal : array of integer;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
StartSearch;
//ShowMessage('goddaw');
end;
//GetFolderLocation('favorites')
function GetFolderLocation(const FolderType: string): string;
{ Henter fra Registry den pladsering dine favoritter har }
var
SFolderKey : string;
begin
//ShowMessage('Stien i regedit er : \Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\ ??');
SFolderKey := '\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\' ;
with TRegistry.Create do
begin
RootKey := HKEY_CURRENT_USER;
if OpenKey(SFolderKey, true) then
Result := ReadString(FolderType)
else
ShowMessage('stien "\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\" kan ikke åbnes');
CloseKey;
Free;
end;
end;
function taelMapper: integer;
var
ok,res : integer;
srRec: TSearchRec;
begin
res := 0;
//ShowMessage(GetFolderLocation('favorites'));
//ShowMessage('Kalder2');
ok :=0;
ok := FindFirst(GetFolderLocation('favorites')+'\*.*', faanyfile, srRec);
while ok = 0 do
begin
ok := FindNext(srRec);
if (srRec.Name <> '.') then
if (copy(srRec.name,length(srRec.name)-3,1)) <> '.' then
inc(res);
end;
FindClose(srRec);
// ShowMessage(inttostr(res));
//res :=9;
Form1.Memo1.Lines.Add('TaelMapper= ' + inttostr(res)) ;
result := res+1;
end;
function FindMappe(S:string): String;
// finder den aktuelle mappes eller fils navn ud fra url
var
I : integer;
res : string;
begin
i := length(S);
if s[i] = '\' then
dec(i);
while s[i] <> '\' do
begin
res := s[i] + res;
dec(i);
end;
result := res;
end;
function URLFromShortcut(const dotURL: string): string;
begin
with TIniFile.Create(dotURL) do
try
try
Result := ReadString('InternetShortcut', 'URL', '') ;
except;
Result := '';
end;
finally
Free;
end;
end;
procedure TForm1.StartSearch;
var
filer: TStringList;
Save_Cursor:TCursor;
antal : integer;
begin
antal := taelMapper-1;
memo1.Lines.Add('antal= '+inttostr(antal));
//ShowMessage() ;
SetLength(arrText, antal);//taelMapper
SetLength(arrtal,antal);//taelMapper
html := '';
Save_Cursor := Screen.Cursor;
Screen.Cursor := crHourGlass; { Show hourglass cursor }
try
filer := TStringList.Create;
try
SearchForFiles(GetFolderLocation('favorites'), filer, True);
//SearchForFiles('C:\Documents and Settings\larsen11\Dokumenter', filer, True);
finally
filer.Free;
end;
finally
Screen.Cursor := Save_Cursor; { Always restore to normal }
end;
end;
procedure TForm1.SearchForFiles( path: string; var Value: TStringList; rec:Boolean);
var
Filtype, kat: string;
srRec: TSearchRec;
ok,test: Integer;
TmpMappe, RowCol, br : string;
begin
//Memo1.Clear;
Filtype := '*.url';
if path[Length(path)] <> '\' then
path := path + '\';
ok := FindFirst(path + filtype, faAnyFile-faDirectory, srRec);
while ok = 0 do
begin
memo1.Lines.Add('findmappe= '+FindMappe(path)+' -- TmpMappe= '+ tmpmappe);
if (srRec.Name[1] <> '.') and (srRec.Name <> '') then
if TmpMappe <> FindMappe(path) then
begin
inc(taller);
AntalIKat := 0;
html := html + '<br>';
TmpMappe := FindMappe(path);
kat := '';
// her skrives overskriften på kolonnen
html := html + ''+#10#13+' <big><b>'+TmpMappe+'</b></big><br>';
end;
// her skrives linkene under overskriften
html := html + ''+#10#13+' <a href="'+URLFromShortcut(path+SRRec.name)+'" title="'+copy(srRec.Name,0,length(srRec.name)-4)+'">'+ copy(srRec.Name,0,length(srRec.name)-4)+'</a> <br>'+br ;
//ListBox1.Items.Add(' '+srRec.Name + ' --> '+ URLFromShortcut(path+SRRec.name));
Inc(AntalIKat);
arrText[taller]:= html;
// MemoBackUp.Lines.Add(TmpMappe+','+URLFromShortcut(path+SRRec.name)+','+copy(srRec.Name,0,length(srRec.name)-4));
// MemoBackUp.Lines.SaveToFile(ExtractFileDir(Application.ExeName) + '\DateToday.smb');
arrTal[taller]:= AntalIKat;
ok := FindNext(srRec);
end;
html:='';
FindClose(srRec);
if rec then // recurse sub-dirs
begin
if path[Length(path)] <> '\' then
path := path + '\';
memo1.Lines.Add('path= '+ path);
ok := FindFirst(path +'*.*', faAnyfile, srRec);
while ok = 0 do
begin
if srRec.Attr and faDirectory > 0 then // it's a directory
if srRec.Name[1] <> '.' then
begin
SearchForFiles( path + srRec.Name, Value, rec);
end;
ok := FindNext(srRec);
end;
FindClose( srRec);
end;
end;
end.
