Come on, admit it:  You die a little inside every time you use the Variants unit.

Comments

  1. That's why I almost never used it =)

    ReplyDelete
  2. And you die twice when using TValue :-)

    Joke apart, Variants and TValue aren't logically different from using polymorphic classes: in both case you can't be sure what you're manipulating, and you can't be sure what a (virtual) method call will do.

    And if you die when using Variants, what happens when you use Interfaces? Interfaces are even more impractical to debug (in the Delphi debugger), and can even aggregate methods across multiple instances, and the concrete methods behind the interface methods can have completely different names.

    ReplyDelete
  3. Interfaces are great for creating coherence across incoherent objects.

    ReplyDelete
  4. Lars Fosdal But under the Delphi, they're mostly great for obfuscating coherent objects during the debugging phase :)
    The debugger is in serious need of a major upgrade wrt to interfaces (and classes for that matter): you can navigate through complex closures with no sweat in Chrome debugger f.i., but throw in a couple interfaces in Delphi, an anonymous method, and you can't inspect squat without extensive manual evaluations with blind casts everywhere (and failing a cast means risking IDE corruption and crash).

    ReplyDelete
  5. That is true - but with a little bit of discipline - it is a useful, albeit sharp and dangerous, tool.

    ReplyDelete
  6. When I use variants (which I do sparingly), it's mostly as an optional/nullable type, something Delphi lacks unfortunately. I never use them in any interface declarations though, just in internal implementations.

    ReplyDelete
  7. Yesterday, I added the Variants unit to my uses clause to make use of the VarToDateTime function. There was a bit of hesitation but it just worked too well to ignore.

    ReplyDelete
  8. Variants are for runtime polymorphism such as user script variables.

    ReplyDelete
  9. I'd rather use Variants than stringly typed code.

    ReplyDelete
  10. Asbjørn Heid  -- You can get Nullable types via the Spring4D framework. Very nice implementation.

    ReplyDelete
  11. Can you plug FireDAC into Spring4D, Nick Hodges ?

    ReplyDelete
  12. Lars Fosdal Not sur what you mean... you don't "plug things in" to Spring4D.

    ReplyDelete
  13. Let me rephrase, Nick Hodges - Can you easily use Spring4D on top of FireDAC (as opposed to on top of dbExpress or ADO) ?

    ReplyDelete
  14. Really? I thought that objects were like cogs that matched together. :-)

    ReplyDelete
  15. You can use the Spring Framework anywhere -- again, not sure what you are asking.  It's not really related to any database framework......

    ReplyDelete
  16. OK, that reveals that I am completely clueless to what Spring4D can do :P

    ReplyDelete
  17. ... or maybe a better answer is this:  Yes, you can.  ;-)  Lars Fosdal

    ReplyDelete
  18. In this case, it has a Nullable type that you can use.  Works a treat.

    ReplyDelete
  19. Nick Hodges Does it handle comparison, algebra, and other operators? Does it propagate through expressions (like in SQL)?

    ReplyDelete
  20. Eric --

    It declares the following overloads:

        { Operator Overloads }
        class operator Implicit(const value: Nullable): T;
        class operator Implicit(const value: T): Nullable;
        class operator Implicit(const value: Nullable): Variant;
        class operator Implicit(const value: Variant): Nullable;
        class operator Implicit(value: Pointer): Nullable;
        class operator Explicit(const value: Nullable): T;
        class operator Equal(const a, b: Nullable) : Boolean;
        class operator NotEqual(const a, b: Nullable) : Boolean;

    ReplyDelete
  21. Nick Hodges Thanks, looks interesting indeed.

    ReplyDelete
  22. I always refrained from Variants. In the beginning because it was processing overhead and nowadays because it's a mess. However, using and extending DevExpress controls i've had to open up this can of worms...

    ReplyDelete

Post a Comment