Hier noch mal die korrekte prozedur, in der ursprünglichen war ein Denkfehler:
Delphi-Quellcode:
{------------------------------------------------------------------------------}
{ Worthäufigkeit ermitteln }
{------------------------------------------------------------------------------}
procedure Occurence(sl: TStrings; Text: string; var WordArray: TWordArray);
var
OuterLoop, InnerLoop: Cardinal;
TextWordList: TStringDynArray;
Count: Cardinal;
begin
TextWordList := Explode(' ', Text);
Count := 1;
// Wortliste durchgehen
for OuterLoop := 0 to sl.Count - 1 do
begin
for InnerLoop := 0 to Length(TextWordList) - 1 do
begin
if sl.Strings[OuterLoop] = TextWordList[InnerLoop] then
inc(Count);
end;
WordArray[OuterLoop].Word := sl.Strings[OuterLoop];
WordArray[OuterLoop].Count := Count;
Count := 1;
if bCancel = 1 then
Break;
end;
end;