Jump to content

Stefan Glienke

  • Content Count

  • Joined

  • Last visited

  • Days Won


Stefan Glienke last won the day on March 11

Stefan Glienke had the most liked content!

Community Reputation

539 Excellent


Technical Information

  • Delphi-Version
    Delphi 10.1 Berlin

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Stefan Glienke

    Overstatic methods

  2. Stefan Glienke

    Generic class

    Generics in Delphi have more severe issues that should be worked on than that tbf
  3. Stefan Glienke

    spring4d list immidiately gets freed

    FToollist is certainly not being freed but the items because the list returned by FindAll has OwnsObjects = True and goes out of scope at the end of the method. Write dm.Session.FindAll<TTool>.MoveTo(FToolllist);
  4. Stefan Glienke

    language updates in 10.4?

    I would like to but I don't (and not because of FUD but because I know of the bugs myself) - do I need to say anything more? Ask around in other languages if people in general trust their compilers and standard runtime libraries or not.
  5. Stefan Glienke

    language updates in 10.4?

  6. Stefan Glienke

    Generics and Classes on Windows 2000 = OOM

    Dynamic arrays cannot leak unless you circumvent the compiler generated code controlling their reference counting.
  7. Stefan Glienke

    Generic class

    FWIW just recently my coworker opened these issues that are related to this topic: https://quality.embarcadero.com/browse/RSP-27799 https://quality.embarcadero.com/browse/RSP-27802
  8. Stefan Glienke

    language updates in 10.4?

    VS is also not perfect but their compiler and language design is rock solid - yes, if you look into C# communties there are also people complaining that stuff is not C#-ish and that but the number of times where the C# compiler just craps itself, kills the entire IDE or simply produces completely wrong code is like several orders of magnitudes less than with Delphi.
  9. Stefan Glienke

    language updates in 10.4?

    YES, exactly that! However many Delphi developers have a troubled past where often "new" things turned out to be broken, caused problems or were simply not thought through entirely and just slapped onto existing things like duck tape. Like using attributes like [ref] in addition to the existing keyword const just because of the fear to introduce new keywords or introducing inline variables (that had many bugs) without the entire tooling understanding them and stopping to work. So many people are in the mindset of "don't touch it so you can't break it" and "fix the existing bugs before adding new broken stuff"
  10. Stefan Glienke

    language updates in 10.4?

    Interesting - even with {$mode delphi} it does not allow that - probably it's yet another of those bazillion switches of FPC to make it behave similar to Delphi - not that I would ever care. Anyhow this is still a thread about Delphi so your approach is not sufficient here imo. @Fr0sT.Brutal It's a little less simplistic than that but basically yes.
  11. Stefan Glienke

    Generic class

    As I wrote before a final method or sealed class will produce a non virtual call in your approach - try again the code from your original post with virtual in TTest1 and override final in TTest2. Also let me add that the fear of virtual method calls is way too high and in most cases it turns out they don't affect the overall performance at all (especially not with some code that the Delphi compiler produces that trashes your performance in other ways) If you call a virtual method in a tight loop and want to avoid the "virtual method address lookup" (again, measure if it really affects anything) that happens every time then you can store it as a method pointer before and then call that one in your loop.
  12. Stefan Glienke

    Generic class

    Then you probably should read them again - they say: warning CS0114: 'TTest2.Test()' hides inherited member 'TTest1.Test()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
  13. Stefan Glienke

    Generic class

    public new is not overriding - that's similar to reintroduce - if you want to override, you write *drumroll* override I would even guess the CLR to be clever enough to devirtualize it entirely
  14. Stefan Glienke

    Generic class

    You make the Test method virtual just like was suggested in the 2nd post for the similar Delphi code. You can then even make the override in TTest2 final or make the class sealed and get a non virtual call generated by the compiler!
  15. Stefan Glienke

    Generic class

    How about you write the code in a proper way: using System; public class TTest1 { public void Test() { Console.WriteLine("TTest1.Test"); } } public class TTest2: TTest1 { public void Test() { Console.WriteLine("TTest2.Test"); } } public class TTest<T> where T: TTest1, new() { public static void TestIt() { var FTest = new T(); FTest.Test(); } } public class Program { public static void Main() { TTest<TTest2>.TestIt(); } } The reason FPC does it different is because its generics are behaving more like C++ templates. However for generics there is no kinda "duck typing" or prototyping. You tell the generic class "look there is the type parameter T, which is guaranteed to be a TTest1 and it has a constructor". So when the compiler generates the AST for the generic type it just takes from these informations and so it decides to emit a static call to TTest1.Test because that is not a virtual method. This is the behavior in all languages with generics that I know of (such as C# or Java) - languages that use a templating approach such as C++ and possibly FPC does it similar decide what to call when the type parameter is being specified. Generics in this case behave the same way as if you would write code like this: procedure TestIt(const t: TTest1); begin t.Test; end; here it will always call TTest1.Test and not TTest2.Test even it t is a TTest2 - simply because there is no polymorphism happening due to the lack of a virtual method call. Personally I would rather call this a bug in FPC - but again it depends on the actual language specification/implementation. Both have their pros and cons. I cannot find the official specification for generics in FPC about this specific point to verify.