Of course you first need to "assign the object" when you create the
list-item:

Procedure AddItem(AWord : String);
Begin
  fStringList.Items.AddObject(AWord, TObject(1));
End;

After that you can simply increase it's value by using

Procedure IncreaseCount(AItemIndex : Integer);
Begin
  fStringList.Objects[AItemIndex] :=
TObject(Succ(Integer(fStringList.Objects[AItemIndex])));
End;

OR:

Procedure IncreaseCount(AItemIndex : Integer);
Var
  I : Integer;
Begin
  I := Integer(fStringList.Objects[AItemIndex]);
  I := I + 1;
  fStringList.Objects[AItemIndex] := TObject(I);
End;

Which does exactly the same, but uses *more* code ;-)

Greetz,

Peter.


-----Oorspronkelijk bericht-----
Van: [email protected] [mailto:[email protected]]namens
David Smith
Verzonden: woensdag 7 oktober 2009 15:36
Aan: [email protected]
Onderwerp: Re: [delphi-en] Re: counting occurances of unique words


  How'd you get it compile without declaring that integer variable? ;-)

Reply via email to