Hi, I want to sort a TStringList but not by the strings in it, but by the Objects. Here's my code:
var
i : integer;
iCount : integer;
idxFound : integer;
someText : string;
s : TStringList;
oneWord : string;
aux : integer;
begin
someText := memo_txtfile.text;
oneWord := '';
s := TStringList.Create;
for i := 1 to length(someText) do begin
aux:=ord(someText[i]);
if aux<33 then begin
idxFound := s.indexof(oneWord);
if idxFound >= 0 then begin
iCount := integer(s.objects[idxFound]);
s.Objects[idxFound] := TObject(iCount + 1);
end
else begin
s.AddObject(oneWord, TObject(1));
end;
oneWord := '';
end
else begin
oneWord := oneWord + someText[i];
end;
end;
if oneWord <> '' then
begin
idxFound := s.indexof(oneWord);
end;
if idxFound >= 0 then begin
iCount := integer(s.objects[idxFound]);
s.Objects[idxFound] := TObject(iCount + 1);
end
else begin
s.AddObject(oneWord, TObject(1));
end;
// put the results on the screen in a text box.
quicksort(s,0,s.Count-1);
memo1.Text := '';
memo1.Lines.Add('Frequency' + #9#9 + 'Word');
for i := 0 to s.Count - 1 do
memo1.Lines.Add(intToStr(integer(s.Objects[i])) + #9#9 + s[i]);
end;
This counts how many words are in the memo_txtfile.