For everyone interested in having nullable basic data types in Object Pascal I suggest looking at my new OLTypes library available at https://bitbucket.org/mihoor/oltypes/wiki/Home.


For everyone interested in having nullable basic data types in Object Pascal I suggest looking at my new OLTypes library available at https://bitbucket.org/mihoor/oltypes/wiki/Home.

The new types are: OLBoolean, OLInteger, OLCurrency, OLDouble, OLDate, OLDateTime and OLString.

I've put each basic data type inside a record type with a flag for being Null and overloaded operators.

As a huge bonus, there are some usefull methods for each data type.

Concider this quick example:

Comments

  1. Thomas Mueller I would not make the types mutable at all (as they currently are). This just leads to defects in code where you use them as properties and mutate the copy just returned from the getter. Explicit operator would be the way to go. Variants and their type conversions are a pita.

    FWIW Spring4D nullables have all that solved. Minus the additional operator overloads depending on the type because that does not work in a compiletime safe way for generics.

    ReplyDelete
  2. Thank you for the comments. I've fixed the divide operators
    and I am considering removal of state changing methods.

    I am not quite convinced however about removing operators for Variants. I want to be able to assign straight form TField.Value.

    What's more, a kind of validation exists at runtime. When one is stubborn and against the common sense needs to assign string to OLInteger for example, one cannot assign just any string: '123' is fine, 'asd' will rise exception.

    ReplyDelete
  3. I am just saying the feedback I got over the years was that people were rather irritated to have invalid code compile because the compiler first turns a not compatible value into a variant to then pass it to the nullable and then raise an exception at runtime although it should have complained at compile time that this is not valid - that is why I removed the variant implicit operator. Just saying, decision is completely yours though :)

    ReplyDelete

Post a Comment