Link to home
Start Free TrialLog in
Avatar of bhchng
bhchng

asked on

Cannot implicitly convert type 'object' to 'QUANTUMAUTOMATIONLib.Browse2Class'

I am converting the following code from VB to C#. It works in VB but seems to be have some problem in C#. It is the limitation in C# ? Any expert advice ?


public frmMain()
{
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
                  
      // Declare global object
      SessionClass objSession;
      QDataAccessClass objDataAccess;
      Browse2Class objBrowser;
                  
      // Get a Session Object.
      objSession = new SessionClass();
                  
      // Get a DataAccess Object.
      objDataAccess = new QDataAccessClass();

      // Get the Browser Object from Session.
      objBrowser = objSession.Browser;   // <-- **** ERROR ****

      // Give the Session Pointer to the DataAccess object.
      objDataAccess.SetSession(objSession);

      }
ASKER CERTIFIED SOLUTION
Avatar of TransBind
TransBind

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bhchng
bhchng

ASKER

It works ! Thanks. But why do we cast it ? 'Object' Type diffierence ?
Avatar of bhchng

ASKER

It does not give an error when compiling. But when running the program, it says "Specified cast is not valid". Doesnt seems to be the solution.
Avatar of bhchng

ASKER

Code in Visual Basic:

'=======================================================================
'Synopsis:      Declare global variables & objects
'-----------------------------------------------------------------------
Option Explicit
Dim objSession As QUANTUMAUTOMATIONLib.Session
Dim WithEvents objDataAccess As QUANTUMAUTOMATIONLib.QDataAccess
Dim objBrowser As QUANTUMAUTOMATIONLib.Browse2
Dim objQualityHelper As QUANTUMAUTOMATIONLib.QQualityHelper


'=======================================================================
'Synopsis:      User Interface Message Handlers
'-----------------------------------------------------------------------


'=======================================================================
'Synopsis:      Create global objects and set it ready for use
'-----------------------------------------------------------------------
Private Sub Form_Load()
' Get a session object for Live DataAccess
Set objSession = New QUANTUMAUTOMATIONLib.Session

' Get a QualityHelper object
Set objQualityHelper = New QUANTUMAUTOMATIONLib.QQualityHelper

' Get the Browser Object from Session.
Set objBrowser = objSession.Browser

End Sub