Using Angle Brackets (I have seen people using TList<PSomething>)
Asked Answered
G

1

3

I see people declaring their TLists like

MyList : TList<PSomeType>;

Whereafter when they create it, they do

MyList := TList<PSomeType>.Create;

So I asume that by doing that, they won't have to typecast the MyList.Items[I] whenever they are using it, like:

ShowMessage( PSomeType(MyList.Items[I]).SomeTextProperty );

So instead they would just do

ShowMessage( MyList.Items[I].SomeTextProperty );

Is that correct?

If so, then why can't I get it to work in Delphi 2010? I am trying exactly that - Declaring my list as

MyList : TList<PSomeType>;

But the compiler says:

Undeclared Identifier: TList<>

What am I doing wrong there?

Goodnight answered 8/4, 2011 at 23:39 Comment(0)
C
15

These people are using a generic list. TList<T> is a generic version of TList, and it's declared in the unit Generics.Collections, not in Classes, where TList is. Add Generics.Collections to your uses list and you should be fine.

Calumniate answered 8/4, 2011 at 23:42 Comment(3)
20 seconds faster. :) +1, and deleting my answer.Lavonda
+1 - will mark as Answer once S.O allows me. Thank you! :) Also, seen your RPG Maker, very nice man!Goodnight
@Jeff: Thanks. It's been a really rewarding project to work on.Calumniate

© 2022 - 2024 — McMap. All rights reserved.