Ok, here is the pertinent code:
Private Sub InstantiateObject(ByVal FullName As String, ByVal
Container As String, ByVal ObjectName As String)
Try
Dim ExternalAssembly As System.Reflection.Assembly = _
System.Reflection.Assembly.LoadFrom(Container)
Dim CalledForm As BravoBaseForm = _
ExternalAssembly.CreateInstance(FullName, True)
CalledForm.Name = ObjectName
Me.FormOwner.AddOwnedForm(CalledForm)
CalledForm.FormUser = Me.MenuUser
CalledForm.FriendlyFormName = FullName
CalledForm.Show()
Catch ex As Exception
Dim ErrorMessageText As String
ErrorMessageText = "Error attempting to run this Option,
contact Software Support" & vbCrLf & _
vbCrLf & "Menuhandler::InstantiateObject" & vbCrLf & _
"Object FullName = " & FullName.Trim & " Container = "
& Container.Trim & _
vbCrLf & "Message: " & ex.Message
Me.MenuUser.BravoMessage.HandleMsg(ErrorMessageTex t, 2)
Me.MenuUser.BravoMessage.HandleMsg(ex.Message, True)
End Try
End Sub
A few things to know/consider. All my forms in this application are
derived ultimately from BravoBaseForm, so I use that as a template to
receive the results of ExternalAssembly.CreateInstance. You could
easily modify this to adapt to other object types.
FullName is the fully qualified name of the object.
Container is the assembly name (usually Exe, but could be a dll)
ObjectName is a unique reference to the form as used in the database
and as a unique id for the running form (we don't allow a form to be
open more than once, you could adjust this pretty easily).
Here is how these parts fit together:
If I have an assembly that compiles as Foo.Exe and there is a form
named FindWidgets.Vb and it is listed in my security table with a
unique id of FindWidget, then I'd call this function as follows:
InstantiateObject("Foo.FindWidgets", "Foo.Exe", "FindWidget")
The heavy lifting in this function is these two lines:
Dim ExternalAssembly As System.Reflection.Assembly = _
System.Reflection.Assembly.LoadFrom(Container)
Dim CalledForm As BravoBaseForm = _
ExternalAssembly.CreateInstance(FullName, True)
The first one basically creates a pointer to the Assembly, Foo.Exe in
my example (Ok, I know there aren't really pointers in .NET, but I'm
old school). The second line drills into the assembly and creates an
instance of the class named Widgets.Vb in my example.
Hopefully this helps!
I'm sending a reply to your email and also posting it in the group for
others to use.
Bill