Array Null until loaded

2 posts, 0 answers
  1. David Hollins
    David  Hollins avatar
    15 posts
    Member since:
    Dec 2009

    Posted 24 May 2010 Link to this post

    I have an object which contains a struct that encapsulates a double[].  The double[] is stored as a blob and all seems to save correctly.  When retrieving the values though, the double[] is null unless I wait for a second before accessing its values.  I am able to get it working if I walk through it in the debugger and slow it down manually but when running it outside of the debugger the array is just null.

    Is this a timing issue of some sorts?  Can I check to see of the object is still loading and wait, etc.

    Some other things to note as well, if I browse into the object in the debugger and access the variable itself it seems to load the value BUT if I access the value while browsing by going through the access method (the property method) then it is null.

    Any help is appreciated!

    Thanks,
    David Hollins
  2. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 25 May 2010 Link to this post

    Hello David,

    I'm sure there is another reason but the 1 second delay. I'm guessing that the debugger variable visualizer steps in here, evaluates the content of the array and that's why it is visible after a short period of time in the debugger. But why is it not visible in a run outside of the debugger? Please note, that OpenAccess uses a technique called 'lazy loading' where not all fields are populated immediately, but upon access to them. Most likely in your case there is an issue with the struct that gets embedded in the class, however. This is when a struct field is returned from a property, the values in the struct must be copied as the returned struct value is actually a copy of the original (embedded in the class). Therefore it can make a difference if you write

    MyInstance.StructFieldProp.ArrayProp

    or have a method double[] MyClass::Read() { return this.StructFieldProp.ArrayProp; }

    In the first case a copy of the whole struct is required logically, in the second case it is not. User defined structs are really non-trivial to understand and although OpenAccess supports them, my advice is not to use them in the persistent model as they tend to create behaviors which are strange on the first sight.

    All the best,
    Thomas
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
Back to Top