Page 4 of 5 FirstFirst 12345 LastLast
Results 31 to 40 of 48

Thread: YAFR DataTypeToJson beyond 19.1

  1. #31
    Join Date
    Feb 2009
    Location
    Stuart, FL
    Posts
    5,321

    Default Re: YAFR DataTypeToJson beyond 19.1

    in C# a nullable type is actually a struct using a generic. But a struct in C# has fields, methods and properties like a class

    for example you can do this

    Nullable<int> myNullableInt;

    or short form

    int? myNullableInt;

    if (myNullableInt.HasValue) {
    int newint = myNullableInt.Value;
    }

    or

    if (myNullableInt != null)
    {
    int newint = myNullableInt;
    }

    and yes pointers by definition support null when they are not pointing to anything

    because they are implemented using generics any type can be made available using the nullable<T> struct
    Last edited by starzen; 17-Apr-2019 at 09:33 AM. Reason: additional
    Michael Salzlechner
    StarZen Technologies, Inc
    http.://www.starzen.com

    IT Director at Balloons Everywhere

    Development Blog
    http://www.salzlechner.com/dev

    DataFlex Package Manager (aka Nuget for DataFlex)
    http://windowsdeveloper.com/dfPackage

  2. #32
    Join Date
    Feb 2009
    Posts
    5,467

    Default Re: YAFR DataTypeToJson beyond 19.1

    Would a nullable Boolean be a thing? Sounds silly... surely the whole point of a Boolean is that it can only be True or False.


    This brings us full circle

    I actually don't mind if null is supported or not, to me that is a separate question, what I want to know (and I want DF to know) is has a value been assigned to a variable

    So yes unassigned or null for a boolean is needed


    As Stazen says these are two different 'values' in the case of Javascript
    Last edited by Focus; 17-Apr-2019 at 09:40 AM.
    Success consists of going from failure to failure without loss of enthusiasm - Winston Churchill

  3. #33
    Join Date
    Feb 2009
    Location
    Adelaide, South Australia
    Posts
    2,863

    Default Re: YAFR DataTypeToJson beyond 19.1

    Null in a Boolean is a thing. Take
    bMarried

    In a web service you pass True,False or null.

    Obviously Null = ‘unknown’.

    When sending you can however leave the node out, and null is explicit.

    When receiving you either do or do not get the null in the json (again explicit), but if you move the json to a struct the program needs to know if it is True, false or Null.
    Marco Kuipers
    DataFlex Consultant
    28 IT Pty Ltd - DataFlex Specialist Consultancy
    DataFlex Channel Partner for Australia and Pacific region
    Adelaide, South Australia
    www.28it.com.au

  4. #34
    Join Date
    Feb 2009
    Location
    UK
    Posts
    826

    Default Re: YAFR DataTypeToJson beyond 19.1

    Hi Mike

    If the language supports NULL then Booleans should also. If NULL then it has not been set, I know how can a binary variable have a third state? But the variable does not have the third state, it’s the “has a value been set” flag that is being changed when a value is assigned to the variable.

    MS SQL keeps a bit map for the columns in each record to indicate if a value has been saved in the column.

    No idea what is happening in Next Gen, but one option would be to implement the “has a value been set” flag for all variables, default it to true and set the value to the current defaults. This keep backward compatibility. We would then need to be able to move NULL to variables to clear the “has a value been set” flag. And a couple of methods to test the “has a value been set” flag, IsNULL and IsNotNULL. (I would like both – saves on parenthesis).

    You need to try and stop thinking of NULL as a value and think of it as a “has a value been set” flag. Took me some time to do this...
    Ian Smith
    (Member of the SigCj project)

  5. #35
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    2,812

    Default Re: YAFR DataTypeToJson beyond 19.1

    Ian

    Re: "stop thinking of NULL as a value and think of it as a “has a value been set” flag" - well in JavaScript (which I occasionally dabble in <g>) undefined and null are two different things... undefined has a type of (typeof)... wait for it... wait for it... undefined, while null has a type of object.

    Paste this into your browser's console (usually found under "Tools" or "Developer Tools" somewhere) and press <Enter>:
    Code:
    console.log("Demo:");
    console.log("=====");
    var foo; 
    console.log("Here foo is", foo, "while null is", null); 
    foo = '"A value"'; 
    console.log("Now foo is the string", foo, "but null is still", null);
    foo = undefined;  // Note: *not* "undefined" in quotes <g>
    console.log("And now foo is", foo, "again"); 
    console.log("And foo's type is", typeof(foo), "while null's type is", typeof(null));
    undefined is also stupidly named since in general (for variables in functions) it means that they have been defined, but just not assigned to (i.e. what you are calling null) yet.

    OTOH, I do actually agree that "has not been assigned to yet" is the right way to think of null. The JavaScript distinction is probably just wrong-headed (give it a break - it was originally written in 10 days! <g>).

    Mike

  6. #36
    Join Date
    Feb 2009
    Location
    Stuart, FL
    Posts
    5,321

    Default Re: YAFR DataTypeToJson beyond 19.1

    in javascript undefined means they have been 'declared' but not 'defined' (as in a value has been assigned to them)

    javascript is a bit different than some other languages because declaring a variable does not set its type. so until it is defined (assigned to) it has no type. It can also change its type during its lifetime as well
    Michael Salzlechner
    StarZen Technologies, Inc
    http.://www.starzen.com

    IT Director at Balloons Everywhere

    Development Blog
    http://www.salzlechner.com/dev

    DataFlex Package Manager (aka Nuget for DataFlex)
    http://windowsdeveloper.com/dfPackage

  7. #37
    Join Date
    Feb 2009
    Location
    Adelaide, South Australia
    Posts
    2,863

    Default Re: YAFR DataTypeToJson beyond 19.1

    I was thought at uni NULL = unknown.

    E.g middle name =“ “
    We know this person does not have a middle name

    middle name = NULL
    We do not know if this person has a middle name or not.
    Marco Kuipers
    DataFlex Consultant
    28 IT Pty Ltd - DataFlex Specialist Consultancy
    DataFlex Channel Partner for Australia and Pacific region
    Adelaide, South Australia
    www.28it.com.au

  8. #38
    Join Date
    Feb 2009
    Location
    Hengelo, Netherlands
    Posts
    10,869

    Default Re: YAFR DataTypeToJson beyond 19.1

    Mike,

    Sounds like a variant to me and DataFlex / VB / ASP / DataFlex Reports has the same feature.
    Regards,
    Data Access Worldwide
    Vincent Oorsprong

  9. #39
    Join Date
    Feb 2009
    Location
    Stuart, FL
    Posts
    5,321

    Default Re: YAFR DataTypeToJson beyond 19.1

    Yes, a variant is a similar construct used in VB,VBA, Delphi and even in C++ when using COM. Technically it is handled differently though. Instead of an object it is a tagged union
    Michael Salzlechner
    StarZen Technologies, Inc
    http.://www.starzen.com

    IT Director at Balloons Everywhere

    Development Blog
    http://www.salzlechner.com/dev

    DataFlex Package Manager (aka Nuget for DataFlex)
    http://windowsdeveloper.com/dfPackage

  10. #40
    Join Date
    Mar 2009
    Location
    Adelaide, South Australia
    Posts
    477

    Default Re: YAFR DataTypeToJson beyond 19.1

    Interesting as it is, I can't help feeling that this topic has got a bit off track. The original post was asking for extra capability in exchanging data between Json and DF structs. Well Json is generally derived from a javascript array structire of Name/Value pairs and presents to DF as an ASCII string of delimited Name/Value pairs. So, only those values which can be supported by ASCII can be in that string. NULL is supported by the control character \0 (zero) which is available in DF as (Character(0)). Other concepts of NULL such as "undefined/not yet defined" are not supported in ASCII so cannot be included in Json unless by agreement between the sender and receiver to nominate an otherwise unused ASCII character for that purpose. Not that I can see why you would want undefined data.

    NULL is no use in DF unless the programmer uses it to carry out some action. In my opinion the best way to handle the issue and achieve all this post wants (and more) is to convert Json into an appropriate struct of Name/Value pairs and thence post to the struct you require with appropriate processing. Or, you could simply use the NVP struct in your code.

    Struct NVP
    String Name
    String Value
    End_Struct

    Struct NVP2
    String Name
    NVP2[] Values
    End Struct

    If you want a simple "single-dimension" Struct you can use NVP[] as the intermediary.
    For more complex Structs you could use NVP2[] (I think). I've never needed to do this but if my NVP2 isn't right I'm sure you can work it out so that you exactly mirror the original javascript array.

    Now you can pass exactly what you want out to the external web-service and make whatever decisions you need about the data which comes back,which of course, doesn't need all the elements of the final struct, without setting any properties.

    Ian
    Last edited by Ianv; 19-Apr-2019 at 09:00 PM.
    The most important leg on a three legged stool is the one that's missing.
    Murphy's Law (2)

Page 4 of 5 FirstFirst 12345 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •