2 Replies Latest reply on Apr 5, 2013 6:24 PM by jbagley

    PBControl casting issues

    jbagley

      Hello everyone,

       

      I am trying to add a OptionButton to a processbook display using C#.  I can get the symbol to be created, but am having trouble casting the symbol as a PBControl afterwards. Originally I was trying to cast the result directly from adding a symbol, but had trouble so I followed Mathieu's advice on this post http://vcampus.osisoft.com/discussion_hall/add_in_microsoft_development/f/11/t/3919.aspx 

       

      I cycled through the symbols and the results were the same as the ones below.

       
      PBObjLib.Symbol radioButton;
      
                  radioButton = sLICDisplay.Symbols.Add(PBObjLib.pbSYMBOLTYPE.pbSymbolControl, "Forms.OptionButton.1") as PBObjLib.Symbol;
                  if (radioButton.Type == (int)PBObjLib.pbSYMBOLTYPE.pbSymbolControl)
                  {
                      PBSymLib.PBControl control = (PBSymLib.PBControl)radioButton;
                      PBSymLib.PBControl control2 = radioButton as PBSymLib.PBControl;
                  }
      

       The line 

       
      PBSymLib.PBControl control = (PBSymLib.PBControl)radioButton;
      

      causes a cast exception and the following line just gives a null.

       

       

       

      The following code works in VBA behind procbook

       

       

       
      Set a = Display1.Symbols.Add(pbSymbolControl, "Forms.OptionButton.1")
      

       where a is a PBControl.

       

       

       

      Any suggestions on how I can grab onto to PBControl symbol so I can set the properties in C#

       

       

       

      Thanks for any help

       

       

        • Re: PBControl casting issues
          mhamel

          @Justin: Probably the cast exception you received is: "Unable to cast object of type 'PBObjLib.SymbolClass' to type 'PBSymLib.PBControl'."

           

          You must know that PI ProcessBook has been built with COM and not .NET. Some .NET interop libraries were written to allow their usage within the .NET world but not everything is accessible.

           

          The Add method does not return the exact same object type if you are on the COM-based world or .NET. On the COM-based world, the casting of the returned object into one of its extended interface works flawlessly but on the .NET side, a different in the definition makes that casting not possible.

           

          One possible way to solve your problem would be to write a C++/CLI library to perform that operation for you and return the PBControl object to your .NET code that would incorporate this aforementioned library.

           

          I hope this helped!