NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

passing object reference to c#

Hi Doug,

 

I don't have exception at the following code:

 PropertyObject propertyObject=uiMsg.ActiveXData as PropertyObject;
 GraphPane g = (GraphPane)propertyObject.GetValInterface("GraphPane", 0);

g variable contains null ...

As you mentioned I have to get exception unless it have been managed by the NI code.

 

Dear doug,

Can you show me a simple .NET example that can be cast and can be referenced by...

 

 

0 Kudos
Message 11 of 12
(1,796 Views)

@NewSCRUser wrote:

Hi Doug,

 

I don't have exception at the following code:

 PropertyObject propertyObject=uiMsg.ActiveXData as PropertyObject;
 GraphPane g = (GraphPane)propertyObject.GetValInterface("GraphPane", 0);

g variable contains null ...

As you mentioned I have to get exception unless it have been managed by the NI code.

 

Dear doug,

Can you show me a simple .NET example that can be cast and can be referenced by...

 

 


Maybe what's happening is that your variable Locals.GraphPane is actually set to NULL in this case, thus GetValInterface is returning NULL so the cast isn't throwing an exception. Make sure you are actually setting Locals.GraphPane to something and make sure that your UIMessage is posted synchronously (i.e. pass true for the Synchronous parameter).

 

Also you could re-write your code as follows to test this theory:

 PropertyObject propertyObject=uiMsg.ActiveXData as PropertyObject;
 Object gObj = propertyObject.GetValInterface("GraphPane", 0);

 

Debug.Assert(gObj != null) // If the assert fails you must not have set the local varible or the UImessage is not being posted synchronously.

 

GraphPane g = (GraphPane) gObj;

 

-Doug

0 Kudos
Message 12 of 12
(1,790 Views)