tags:

views:

17

answers:

1

Hello,

I'm having trouble creating a global array that i can use in other functions.

I have this code right under "Public Class myClass":

Dim LoadedPlugins As Array

Then in a function I have this:

Dim PluginList As String() = Directory.GetFiles(appDir, "*.dll")
For Each Plugin As String In PluginList
Dim Asm As Assembly
Dim SysTypes As System.Type
Asm = Assembly.LoadFrom(Plugin)
SysTypes = Asm.GetType(Asm.GetName.Name + ".frmMain")
Dim IsForm As Boolean = GetType(Form).IsAssignableFrom(SysTypes)
If IsForm Then
        Dim tmpPlugin As PluginAPI = CType(Activator.CreateInstance(SysTypes), PluginAPI)
        LoadedPlugins(count) = tmpPlugin

In the Interface file I have:

Public Interface PluginAPI
Function PluginTitle() As String
Function PluginVersion() As String
Function CustomFunction() As Boolean
End Interface

Now obviously that doesn't work, how can I add the tmpPlugin to an array or list so I can use it in other functions?

The main thing I need to be able to do is loop through all the loaded plugins and execute the CustomFunction in a separate function than the one that loads the plugins listed above.

Can anyone help me?

A: 

Use this for your dim: Public Shared LoadedPlugins As Array

However I notice a few things
Some tips to make writing programs faster (in the end, but more thinking for design):

  • use Option Strict.
  • give LoadedPlugins a type (PluginAPI)
  • use a generic list instead of array
  • don't use globals. Figure out a way to give this info to the classes that need it
    • this is a bit of an art. But don't give up - 5 programs later you will have it down!
FastAl
the public shared helped me out and your other tips were useful.I did manage to solve my issue using:Public Shared LoadedPlugins(10) As ObjectLoadedPlugins(count) = tmpPlugin
Joe