By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Dynamically Loading Programs

P: n/a
Our company wants to standardize all our new programs. We are using .NET
2.0 and VB.NET against an Oracle Database and SQL Server Database. One
suggestion was to have a single sign on and based on the sign on, list the
programs available to the user. The user would select the program they want
and it would load the program for them in like an MDI application. I would
like to make this like an MDI form that has a Shell application that
controls the login and display of the programs. The shell application would
have a tool strip and status strip that would apply to all programs. Then
in the shell program display the program. Can this be done with an MDI
program? Any help (documentation ,example etc) would be great. I want to
jump on this ASAP so we aren't doing programs piece meal. Thanks.

Mar 28 '06 #1
Share this Question
Share on Google+
2 Replies

P: n/a
Not sure if this will help, but....

I had a need to display options to the user in a tree control. The
available programs (forms) were determined by a security application so
at run time, I didn't know what items may or may not be listed on the
menu tree.

To avoid a very lengthy case/select statements that would need to be
modified everytime I added a new form, I used reflection to solve my

My wife just called, she's out front waiting for me (we carpool). IF
this sounds like something that might help you, let me know and I'll
share the few lines of code necessary to make this happen.


Mar 28 '06 #2

P: n/a
Ok, here is the pertinent code:

Private Sub InstantiateObject(ByVal FullName As String, ByVal
Container As String, ByVal ObjectName As String)
Dim ExternalAssembly As System.Reflection.Assembly = _
Dim CalledForm As BravoBaseForm = _
ExternalAssembly.CreateInstance(FullName, True)
CalledForm.Name = ObjectName
CalledForm.FormUser = Me.MenuUser
CalledForm.FriendlyFormName = FullName
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 = _
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.


Mar 29 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.