G
Giovanni Bassi
Hello all,
I have prepared a simple procedure to open forms only once. Here it is:
-//-
Private Sub OpenChildForm(ByRef objFormToOpen As
System.Windows.Forms.Form, ByVal TypeToCreate As String)
If Not CheckFormOpen(objFormToOpen) Then
Return
End If
objFormToOpen =
CType(Activator.CreateInstance(Type.GetType(TypeToCreate)), Form)
objFormToOpen.MdiParent = Me
objFormToOpen.Show()
End Sub
Private Function CheckFormOpen(ByVal objFrm As Form) As Boolean
If Array.IndexOf(Me.MdiChildren, objFrm) <> -1 Then
MessageBox.Show("Table already open.", "", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Return False
Else
Return True
End If
End Function
-//-
The problem is:
When I call it like this:
OpenChildForm(m_objfrmAccounts,
"CoairBR.Accounting.PayrollTranslator.frmAccounts")
the opened form reference is passed back to m_objfrmAccounts.
But if I call it like this:
OpenChildForm(CType(m_objfrmAccounts, frmAccounts),
"CoairBR.Accounting.PayrollTranslator.frmAccounts")
m_objfrmAccounts is nothing, even after the form opens. No reference is
passed back to m_objfrmAccounts, even though I am calling OpenChildForm with
the objFormToOpen argument passed by reference.
I am using Option Strict On, but I can't use it On anymore, otherwise:
OpenChildForm(m_objfrmAccounts,
"CoairBR.Accounting.PayrollTranslator.frmAccounts")
won't compile, as I need an explicit conversion from m_frmAccounts to a
System.Windows.Forms.Form.
By the way, I don't know if it matters, but frmAccounts is derived from
another form using visual inheritance and not directly from Form.
What do I do? Why is CType keeping the reference value from being set?
Thanks!
Giovanni Bassi
I have prepared a simple procedure to open forms only once. Here it is:
-//-
Private Sub OpenChildForm(ByRef objFormToOpen As
System.Windows.Forms.Form, ByVal TypeToCreate As String)
If Not CheckFormOpen(objFormToOpen) Then
Return
End If
objFormToOpen =
CType(Activator.CreateInstance(Type.GetType(TypeToCreate)), Form)
objFormToOpen.MdiParent = Me
objFormToOpen.Show()
End Sub
Private Function CheckFormOpen(ByVal objFrm As Form) As Boolean
If Array.IndexOf(Me.MdiChildren, objFrm) <> -1 Then
MessageBox.Show("Table already open.", "", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Return False
Else
Return True
End If
End Function
-//-
The problem is:
When I call it like this:
OpenChildForm(m_objfrmAccounts,
"CoairBR.Accounting.PayrollTranslator.frmAccounts")
the opened form reference is passed back to m_objfrmAccounts.
But if I call it like this:
OpenChildForm(CType(m_objfrmAccounts, frmAccounts),
"CoairBR.Accounting.PayrollTranslator.frmAccounts")
m_objfrmAccounts is nothing, even after the form opens. No reference is
passed back to m_objfrmAccounts, even though I am calling OpenChildForm with
the objFormToOpen argument passed by reference.
I am using Option Strict On, but I can't use it On anymore, otherwise:
OpenChildForm(m_objfrmAccounts,
"CoairBR.Accounting.PayrollTranslator.frmAccounts")
won't compile, as I need an explicit conversion from m_frmAccounts to a
System.Windows.Forms.Form.
By the way, I don't know if it matters, but frmAccounts is derived from
another form using visual inheritance and not directly from Form.
What do I do? Why is CType keeping the reference value from being set?
Thanks!
Giovanni Bassi