Hi,
ersteinmal der Source (das mit try...finally kommt noch):
Delphi-Quellcode:
// ------ Fileoperations -- start -----
//Erweiterung entfernen
function GetToken(aString, SepChar: string; TokenNum: Byte): string;
var
Token: string;
StrLen: Byte;
Num: Byte;
EndofToken: Byte;
begin
StrLen := Length(aString);
Num := 1;
EndofToken := StrLen;
while ((Num <= TokenNum) and (EndofToken <> 0)) do
begin
EndofToken := Pos(SepChar, aString);
if EndofToken <> 0 then
begin
Token := Copy(aString, 1, EndofToken - 1);
Delete(aString, 1, EndofToken);
Inc(Num);
end
else
Token := aString;
end;
if Num >= TokenNum then
Result := Token
else
Result := '';
end;
function getAllFiles(path: string): TStringList;
var
tempResult: TStringList;
s: string;
i : integer;
stl : tstringlist;
lastindex: integer;
begin
tempResult := TStringList.Create;
s := path;
stl:=tstringlist.Create;
lastindex := -1;
try
for i := 0 to tempResult.count - 1 do
begin
stl.Add(GetToken(tempResult.strings[lastIndex], '.', 1));
inc(lastIndex);
end;
tempResult.CommaText:=stl.commatext;
finally
stl.Free;
end;
result := tempResult;
end;
// ------ Fileoperations -- end -----
procedure updateList(TreeView: TTreeView);
var
langs: TStringList;
entries: TStringList;
newMainNode: TTreeNode;
newLangNode: TTreeNode;
i, j: integer;
begin
langs := TStringList.Create;
langs.LoadFromFile(MAIN_PATH+'languages.clf');
langs.Sorted := true;
TreeView.Items.Clear;
newMainNode := Treeview.Items.Add(nil, 'CodeLib');
for i := 0 to langs.Count-1 do begin
newLangNode := TreeView.Items.AddChild(newMainNode, langs[i]);
entries := TStringList.Create;
entries := getAllFiles(MAIN_PATH+langs[i]+'\*.*'#0);
// ShowMessage(IntToStr(entries.count)+#13#10+MAIN_PATH+langs[i]+'\*.*'#0);
for j := 0 to entries.Count do begin
TreeView.Items.AddChild(newLangNode, entries.Strings[j]);
end;
entries.Free;
end;
end;
So, wenn ich nun in der FormCreate-Methode "UpdateList" schreibe, dann kommt der Fehler "ListIndex out of bounds(0)".
Das kann aber nicht sein, da das Verzeichnis nicht leer ist... Was isr falsch?
Chris