10-08-2010 08:28 AM
Hi all,
When I use LabView7.1 and 8.5 with invoke node of .NET, I found different behavior in terms of the input/output terminal. In LV7.1, every parameter has both input and output terminals; but in LV8.5, only the parameter claimed as ByRef has output terminal.
There are 2 problems:
1, In .NET, even if a object parameter is claimed as ByVal, since it is reference type, it still can be modified inside the assembly. So in LV8.5, how to pass the argument after modification, since there is not output terminal?
2, In LV7.1, if the parameter is claimed as ByRef, its type will be changed to .NET object. It is really annoying. I have a String argument to pass into assembly, and the parameter is claimed as "ByRef ... As String", then the input node changes to be an object in place of original String type. But how can I convert the normal String constant to be a .NET object?
Can any Guru give me instructions? Thanks.
Solved! Go to Solution.
10-08-2010 09:08 AM
I add in a picture to describe my questions
Please notice the "SelectVal" parameter. It in fact is just a string. But if I use LV7.1 as the right picture, it becomes an object because it is ByRef.
10-08-2010 09:34 AM
The first thing you have to remember is that LabVIEW 7.1 had marginal support for .NET. LabVIEW 7.1.1f2 fixed a bunch of problems, including supporting .NET 2.0. I use 8.2 primarily, and even that version has questionable support for a lot of .NET. What you are seeing in 7.1 with respect to the string parameter being treated as a .NET object is incorrect behavior. Can't be fixed - the problem is with LabVIEW. I have no idea if using the "To .NET Object" would even work in that case. What you are seeing in LabVIEW 8.5 is correct behavior.
As for question (1), there's really nothing you should need to do. You do not need an output terminal. Since it's a reference type it just points to a place in memory. Just continue the wire.
10-08-2010 10:02 AM
Smercurio,
Your post is really precious! So even "To.NET Object" can't work? I just Googled this method and wanted to resort to it. Desperate.
I know in text language reference points to memory, so that i can directly use the reference after modification of the content. But in LabView, you know the reference is passed by a "wire". So you mean, just after the crosspoint of the callee, the wire changes its value? Amazing, but confusing too. If I stretch 2 lines from same object, one of them is passed into an .NET assembly, while the other one is not, what will happen? I really think to use "output" terminal can avoid ambiguity.
10-08-2010 10:46 AM - edited 10-08-2010 10:47 AM
@steady wrote:
Smercurio,
Your post is really precious! So even "To.NET Object" can't work? I just Googled this method and wanted to resort to it. Desperate.
I didn't say it "can't work". I said I didn't know if it would work. Please don't put words in my mouth.
I know in text language reference points to memory, so that i can directly use the reference after modification of the content. But in LabView, you know the reference is passed by a "wire". So you mean, just after the crosspoint of the callee, the wire changes its value? Amazing, but confusing too. If I stretch 2 lines from same object, one of them is passed into an .NET assembly, while the other one is not, what will happen? I really think to use "output" terminal can avoid ambiguity.
If you're dealing with an object the information will be valid since the wire is the value of the reference, not the value of the contents of the object. For example, if you create this simple assembly:
using System;
using System.Collections;
using System.Text;
namespace StringReverse
{
public class Class1
{
public void ReverseString(ref string stringToReverse)
{
char[] rev = stringToReverse.ToCharArray();
Array.Reverse(rev);
stringToReverse = (new string(rev));
}
public void AddToArray(ArrayList array)
{
array.Add("hello");
}
}
}
Then if you create an ArrayList object on the block diagram you can see the change in the object as shown below:
10-08-2010 08:47 PM
It is so kind of you for providing the sample. I must give you a Kudos. Thanks again.