#
#
#2018-07-24 20:45:33
Delphi
#, 2018-07-24 20:45:33

Perhaps a funny question, but - is there an analogue of "C# extension methods" in Delphi?

I don't even know what's better? quote? or provide a link? there was a question about debugging in C #, there I just illustrated my favorite tricks .. I'll try to make a big quote:

you can implement your simplest logger as an extension (in a utility static class), example
internal static void log(this string txt) => tbLog.AppendText(txt + Environment.NewLine);

then very convenient to use anywhere
$"что то прошло не так, параметры первый {} и второй {}".log();

... and more convenient compiler options, for constructs that are clearly not needed in production
#if DEBUG
            var sw = new Stopwatch();
            sw.Start();
#endif
            /// что то делаем
#if DEBUG
            sw.Stop();
            var ts = sw.Elapsed;
            $"total time:".log();
            $"\t{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds:000}".log();
#endif

.. I repeat - Delphi is released by the community ... but after the sweet habits ... is it worth it?
another question - if there are still saccharins there
ps if there are saccharins in Lazarus - I will still be grateful for the info

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2018-07-24
@mindtester

Extension method : XE3+, helper class.
docwiki.embarcadero.com/RADStudio/Tokyo/en/Class_a...
Conditional compilation : ever since Pipe Pascal, compiler directives

{$IFDEF DEBUG}
{$ENDIF}
docwiki.embarcadero.com/RADStudio/Tokyo/en/Conditi...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question