Skip to content

Better support for 'for..in' loops in TCollection-derived classes #671

@rlebeau

Description

@rlebeau

For example, when using a for..in loop to iterate through a TIdStackLocalAddressList from TIdStack.GetLocalAddressList(), the loop variable is of type TCollectionItem instead of TIdStackLocalAddress, thus requiring a typecast to access members of TIdStackLocalAddress:

var List: TIdStackLocalAddressList;
GStack.GetLocalAddressList(List);
for var item in List do
begin
  item.IPAddress; // error 
  TIdStackLocalAddress(item).IPAddress; // ok
end;

This is because the loop enumerator is implemented by the base TCollection class. TIdStackLocalAddressList would need to implement its own enumerator in order to expose access to its TIdStackLocalAddress elements.

The same issue exists for other TCollection-derived classes in Indy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Element: Compiler/IDEIssues related to a particular Compiler and/or IDEStatus: ReportedIssue has been reported for reviewType: EnhancementIssue is proposing a new feature/enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions