The TInterfaceListIterator object provides an enumeration of all the interfaces in a RSInterfaceCollections.TInterfaceListPersistent object, it implements the CommonInterfaces.IInterfaceIterator interface. It effectively hides the underlying implementation, in this case a TInterfaceListPersistent, while still allowing access to all the interfaces stored in the implementation.
The object provides functionality similar to an Enumeration in Java.
To use the iterator is simple, get the iterator and then keep calling the RSInterfaceCollections.TInterfaceListIterator.NextElement method until the RSInterfaceCollections.TInterfaceListIterator.HasMoreElements method returns False. The iterator works by giving you the next element until the end of the list, there is no provision for getting the previous element. The iterator manages its own memory and will free itself when it is completely dereferenced (as long as you use an interface to access it).
Namespace: RSInterfaceCollections
TInterfacedObject
RSInterfaceCollections.TInterfaceListIterator
|
|
Name
|
Description
|
|
CurrentElement
|
Returns the current interface item in the enumeration, your "place" in the enumeration.
When the iterator is first supplied or when it is RSInterfaceCollections.TInterfaceListIterator.Reset , there is no current element (calling this method in such a case would raise an exception). Only after the first call to the RSInterfaceCollections.TInterfaceListIterator.NextElement method will this method return a value. Unlike the NextElement method which returns a new value every time you call it, this method always returns the same value no matter how many times you call it (until NextElement is called, of course).
This method is part of the CommonInterfaces.IInterfaceIterator interface.
|
|
GetCount
|
Accessor method for the RSInterfaceCollections.TInterfaceListIterator.Count property.
|
|
GetCurrent
|
Returns the current interface item in the enumeration, your "place" in the enumeration.
|
|
get_Count
|
Accessor method for the RSInterfaceCollections.TInterfaceListIterator.Count property.
|
|
HasMoreElements
|
Returns True if there are more elements to retrieve from the enumeration. While this method returns true, the RSInterfaceCollections.TInterfaceListIterator.NextElement method will not raise an exception.
This method is part of the CommonInterfaces.IInterfaceIterator interface.
|
|
MoveNext
|
Returns the next item in the enumeration. If there are no more items, the method will raise an exception.
|
|
NextElement
|
Returns the next item in the enumeration. If there are no more items, the method will raise an exception. To check if there are more items, use the RSInterfaceCollections.TInterfaceListIterator.HasMoreElements method. The NextElement method advances its place in the enumeration and then returns that item. Every call to NextElement returns a new item (until the end of the enumeration). If you wish to access the current item multiple times in a loop, use the RSInterfaceCollections.TInterfaceListIterator.CurrentElement method.
This method is part of the CommonInterfaces.IInterfaceIterator interface.
|
|
Reset
|
Resets the iterator to the beginning of the enumeration.
This method is part of the CommonInterfaces.IInterfaceIterator interface.
|
Top
|
The following code shows how to use the iterator to get all the values in a TInterfaceListPersistent object, note that this code assumes that every interface in the list is an IFact interface:
Delphi
|
var
Values: IInterfaceIterator;
begin
Values := TInterfaceListIterator.Create( InterfaceList );
while Values.HasMoreElements do
ShowMessage( (Values.NextElement as IFact).ToString );
end;
|
|