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(o bjSession) ;
}
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(o
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
Code in Visual Basic:
'========================= ========== ========== ========== ========== ======
'Synopsis: Declare global variables & objects
'------------------------- ---------- ---------- ---------- ---------- ------
Option Explicit
Dim objSession As QUANTUMAUTOMATIONLib.Sessi on
Dim WithEvents objDataAccess As QUANTUMAUTOMATIONLib.QData Access
Dim objBrowser As QUANTUMAUTOMATIONLib.Brows e2
Dim objQualityHelper As QUANTUMAUTOMATIONLib.QQual ityHelper
'========================= ========== ========== ========== ========== ======
'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.Sessi on
' Get a QualityHelper object
Set objQualityHelper = New QUANTUMAUTOMATIONLib.QQual ityHelper
' Get the Browser Object from Session.
Set objBrowser = objSession.Browser
End Sub
'=========================
'Synopsis: Declare global variables & objects
'-------------------------
Option Explicit
Dim objSession As QUANTUMAUTOMATIONLib.Sessi
Dim WithEvents objDataAccess As QUANTUMAUTOMATIONLib.QData
Dim objBrowser As QUANTUMAUTOMATIONLib.Brows
Dim objQualityHelper As QUANTUMAUTOMATIONLib.QQual
'=========================
'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.Sessi
' Get a QualityHelper object
Set objQualityHelper = New QUANTUMAUTOMATIONLib.QQual
' Get the Browser Object from Session.
Set objBrowser = objSession.Browser
End Sub
ASKER