Welcome, Guest
Username: Password: Remember me
Visual Objects

Please use this forum to post questions about Visual Objects and Vulcan.NET
  • Page:
  • 1

TOPIC:

Passing Objects From C# to back to VO 03 Aug 2021 14:13 #19239

  • jeromegorlick
  • jeromegorlick's Avatar
  • Topic Author


  • Posts: 7
  • Hey,

    I work in a program that is a hybrid of VO and C#. any new large development that can be done in c# and called from VO is. My problem is that I'm currently trying to pass an object from C# back to vo and having issues. currently I am passing an Object which has a int status and an array of embeddedobject. I can read the status fine from the original object but when I try to interact with with the embeddedobject array it appears to give me a pointer for each of the embedded objects. I did have some success passing object array back to a seperate method in c# with an index to retrieve a single object and simply iterate through each of the objects that way. It is super hacky but it gives me the object and I can access its internals however once I put these objects into an array and pass the array on to another method I am met with object references again. Has anyone had success with passing objects from c# back to VO. is there any specific datatypes within the object that might be causing it to respond in an unexpected way. Any help or suggestions is much appreciated.

    Regards Jerome

    Please Log in or Create an account to join the conversation.

    Passing Objects From C# to back to VO 14 Mar 2022 01:28 #21918

    • jeromegorlick
    • jeromegorlick's Avatar
    • Topic Author


  • Posts: 7
  • Update with solution, originally when we could not solve this problem we created as stack in .NET and retrieved items from the stack until null was returned to ensure we retrieved all of the required objects from .NET however the cause and solution has now been determined for arrays not passing to VO correctly. As part of another ticket I discovered that the reason behind the array not passing back properly was that .NET arrays are zero indexed but VO expects one indexed arrays. This can be solved by creating a one indexed array in .NET before passing the array to VO. This ensures compatibility with VO and we have had success passing complex objects reliably from .NET back to VO to help facilitate new API functionality from within our software. Hoping that this will help others in the future maintaining old VO code bases with new functionality implemented in .NET.

    Warm Regards,
    Jerome

    Please Log in or Create an account to join the conversation.

    Passing Objects From C# to back to VO 14 Mar 2022 12:55 #21922

    • ic2
    • ic2's Avatar


  • Posts: 1574
  • Hello Jerome,

    I thought that it was not possible to pass C# arrays to VO, and not because of the zero based C# arrays, as these are supposed to be incompatible.

    I convert C# arrays to a string (with a array2strng/string2array function) first. It's not ideal but it works for my purpose. If the array contains objects this won't work.

    Dick

    Please Log in or Create an account to join the conversation.

    Passing Objects From C# to back to VO 14 Mar 2022 13:14 #21923

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3245
  • Hi Jerome,
    I'm using COM very successfully to use .NET objects with their classes and methods in VO.
    But I'm using the VO GUI classes and the SxS mechanism.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Passing Objects From C# to back to VO 14 Mar 2022 22:48 #21929

    • jeromegorlick
    • jeromegorlick's Avatar
    • Topic Author


  • Posts: 7
  • Here is the code we are using to pass an array back to VO, I hope this helps. Not sure why it is said to not work when it seems to be working flawlessly for us.

    c#
    public Array GetNetObject()
        {
            Array voReturnArray = Array.CreateInstance(typeof(object), new[] { NetList.Count }, new[] { 1 });
            Array.Copy(NetList.ToArray(), 0, voReturnArray, 1, NetList.Count);
            return voReturnArray;
        }

    Please Log in or Create an account to join the conversation.

    Passing Objects From C# to back to VO 14 Mar 2022 23:12 #21931

    • ic2
    • ic2's Avatar


  • Posts: 1574
  • Hello Jerome,

    That's absolutely interesting, thanks.

    I was told long ago that this couldn't be done. Can't find it back now however. Probably even way back to Vulcan, and X# dealt with that at some point?

    My conversion Array2String works but if I can pass arrays from C# unchanged it would be a lot easier for some data.

    Dick

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1