VarToStr issue?

Issue #232 closed
Former user created an issue

Hi.

In Delphi, the instruction:

VarToStr (null)

returns the empty string.

In DWS it returns the string "Null".

Is this a deliberate behavior or is it an anomaly?

Thanks.

Comments (4)

  1. Eric Grange repo owner

    Yes, it's an explicit behavior defined in dwsUtils.VariantToString

    VarToStr() in DWS minimizes reliance on the Delphi RTL's VarToStr() implementation in an attempt to preserve more information and avoid various stability and safety issues.

  2. Anders@Melander

    I can’t think of a single case where I have wanted (and expected) VarToStr to return anything other than an empty string on null. The current behavior is just an annoyance which must be worked around.

  3. Eric Grange repo owner

    IIRC initial motivation was when dealing with data coming from a database that distinguishes between null and empty strings (ie. any DB except Oracle), as “null” is only sporadically encountered outside that context. Unassigned maps to an empty string, and is the common value outside database uses.

    I’ll add a variable to specify a custom string representation for null.

  4. Log in to comment