First of all,
Iterate is a lame name for that interface, it should be called
Iterator, so I will be calling it
Iterator in this answer, because I am allergic to bad naming.
You say that you encounter this issue often, and I have to believe you, but I also ought to mention my experience, which is that I have rarely, if ever, encountered this need in the last couple of decades that I have been doing OOP.
Usually, when such a need appears to arise, it is an indication that some other aspect of the design needs refactoring.
The first suspect to examine is the
CopyTable() function: why does it need both an
Iterator and a
Streamable for both the source and the destination table? Why can't it just stream-out the source table to bytes and then stream-in the bytes into the destination table? And why is it even called
CopyTable when it is probably just
CopyStreamableIterator() at worse?
If there is nothing that can be done about the function, then the best approach in my opinion is to combine the two interfaces into one. The name
CopyStreamableIterator() which describes what the function does immediately tells you that you need a
StreamableIterator interface which combines
Iterator. There is nothing wrong with that, and you do not even have to make your
Table class implement that new interface, you can simply implement a
StreamableIteratorDecorator (see decorator pattern) which accepts a
Streamable and an
Iterator as constructor parameters and implements the
StreamableIterator interface by delegating to them. (Though you will probably just declare your
Table class as implementing this interface to be done real quick, because your
Table already implements these methods, so it is good to go.)
Note: I am presuming that in Delphi, just as in Java and C#, a class may extend only one class but multiple interfaces, and that an interface may also extend multiple interfaces, but even if by any chance this is not true, this functionality can be emulated by aggregating interface implementations into classes and adding to classes and interfaces methods that return sub-interfaces.
Thinking about it a bit more, I am realizing that your problem may lie in that ill-named
IIterate interface. This interface is trying to cut corners, so it is built in such a way as to force manipulation of the internal state of the underlying (implementing) object. This causes problems, because it is forcing you to have two separate interfaces, one for altering the internal state of your table to select a row, and another interface for reading/writing the currently selected row.
In a language like C# and Java your table would implement
IIterable<T> would have just one method,
newIterator() : IIterator<T>. In turn,
IIterator<T> would be defined as follows:
IIterator<T> = interface //javaesque
function Next : T;
property EOF: boolean;
or as follows:
IIterator<T> = interface //csharpesque
function Current : T;
function HasNext : boolean;
So, instead of selecting rows, your iteration would be yielding each row which can then be streamed. So, you only need to pass an iterator (or better yet an iterable) to your
Adding rows to the target table can be easily accomplished by implementing a
IConsumer<IStreamable> interface which simply appends the contents of the
IStreamable as a new row at the end of the table.