I am converting a C# code into Delphi 2010.I am stuck on finding an equivalent of yield return of C# in delphi. Can anyone help?
There is simply no equivalent. Delphi does not have any matching functionality. In C# yield return is used in C# iterator methods, and Delphi does not have anything remotely like C# iterator methods.
In Delphi you need to write iterators manually, without the syntactic sugar of iterator methods. This is described in the documentation.
There are at least two implementations of Yield in delphi (both not ideal, though).
First is using asm magic, here: http://santonov.blogspot.ru/2007/10/yield-you.html
Second is using Win32 fibers(very lightweight threads), so will work only on windows. It's here: http://www.gerixsoft.com/blog/delphi/yield
There is one more, slightly less readable, implementation based on fibers: http://delphisorcery.blogspot.ru/2011/04/yield-return-and-delphi.html
That said, i won't recommend using yield if you are new with Delphi, because it is not common way of programming in Delphi. So use it only if you understand consequences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With