2

I know that when I add a collection item to a collection, the index is zero-based. I would like to make it one-based and show the value in a property called Id. Can someone tell me how I can go about this in code?

TCVSClassItem = class(TCollectionItem)  
private  
 fId: Integer;  
 function GetId: Integer;  
public  
published  
 property Id: Integer read GetId;  
end;  

function TCVSClassItem.GetId: Integer;  
begin  
 result:=  ????  
end;
menjaraz
  • 7,551
  • 4
  • 41
  • 81
IElite
  • 1,818
  • 9
  • 39
  • 64
  • Beware. `TCollectionItem` already has [a property named `ID`](http://docwiki.embarcadero.com/VCL/en/Classes.TCollectionItem.ID). Also, there's little point in making a property published if it can't be edited since it won't be displayed in the Object Inspector. – Rob Kennedy Dec 29 '10 at 00:32
  • OK, thanks, but, it was an example...so lets say the property name is SeqNo – IElite Dec 29 '10 at 00:46

1 Answers1

4

result := Index+1 should do it if I understand correctly your needs

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • You understood it correctly. It is the answer and what i was looking for. I had that earlier and could not compile. Turns out it was another issue. Thanks for keeping me on course. – IElite Dec 29 '10 at 00:54