Join us for a Q&A session on Spring4D, its history, uses and future. Stefan Glienke will be online with us to answer your questions.
If you are new to Spring4D or looking for a refresher before the event, Stefan presents an introduction to the library at Devcon Spring4D
Monday, 19th June, 6:00 pm AEST start for 6:15. Stefan’s presentation will start at 7:00 pm.
Zoom details will be posted before the event starts.
This is already possible - you can give such interface a guid but you should be careful about using that with supports and alike because then you can get from MyInterface<Banana> to MyInterface<Elephant> which is hardly compatible. This is why some people don’t put guids on their generic interfaces
What we were talking during the Q&A was this (which is not possible):
type
IMyInterface = interface
function Get<T>: T;
end;
This is a generic method where the generic parameter is on the method. While these methods are possible on classes or records they are not on interfaces. This is because interfaces in Delphi are always implemented as COM interfaces and those have a fixed list of methods. With a generic method you can have numerous different implementations of those methods depending on the type parameter. Thus as with generics in Delphi they get generated by the compiler when they occur in the code. Some place might call Get<Integer> and another might call Get<string> and thus the compiler would emit the code from the Get method for Integer and for string.
We mentioned that this could be possible if we had interface helpers because then that method could be put into the helper and not part of the interface itself. Then of course the code for the Get<T> could only operate on other members of the interface its a helper for because this method would not be implemented by anyone implementing IMyInterface.