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

倾然丶 夕夏残阳落幕 提交于 2019-12-07 23:21:14

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5601822/using-angle-brackets-i-have-seen-people-using-tlistpsomething

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!