VB HELP: Sharing A Variable From Win Application To Dynamically Added Control

  • Thread starter Thread starter Daniel Friend
  • Start date Start date
D

Daniel Friend

I have an application and use custom user controls as plugins. Is there any
way to communicate back and forth from control to app. NOTE: The control is
not refrenced in the app, it will act as a plugin and will be dynamically
loaded to the app.

Example:

1. My application as a public variable
2. The control must receieve the value of the public variable
3. The control will do some math and encryption of the variable
4. The control will return the value to the main application
5. The application will display the results

Any help on how to communicate back and forth with the dynamically created
control will be greatly appreciated!

Thanks,

Dan
 
Daniel Friend said:
I have an application and use custom user controls as plugins.
Is there any way to communicate back and forth from control
to app. NOTE: The control is not referenced in the app

I'd do it this way:

Every Plug-In implements this Interface:

Public Interface IPlugIn
WriteOnly Property ParentForm as IPlugInContainer
' Any other properties/methods that the main application
' might ask /every/ plug-in to do.
End Interface

Have the main application implement this Interface:

Public Interface IPlugInContainer
' Include any properties/methods that a Plug-In might need.
' /Don't/ rely on properties that /happen/ to be on the Form
End Interface

Both of these exist in an assembly common to both the application
and the plug-ins. They form a well-defined communication channel
between plug-in and application; a common currency that the two
can "converse" in.

As you load [each] plug-in into your application, assign the Form
to the [IPlugIn].ParentForm property (you *know* it's there
because the plug-in, whatever /else/ it does, implements the Interface),
as in

' Get Plug-In object
oLoadedPlugIn = Activator.CreateInstance( ...

' Pass the parent application [form] reference to the plug-in
DirectCast( oLoadedPlugIn, IPlugIn ).ParentForm _
= DirectCast( Me, IPlugInContainer )

Your plug-in can now access anything in the IPlugInContainer
Interface (which, of course, calls methods in the main application).

HTH,
Phill W.
 
If the control is created by the application can you create it based off of
MustInherit class?

Public MustInherit Class DynControl

Public ReadOnly Property MyCalulations () as Object (or whatever)

Public Event ImDoneCalculating (ByVal sender As Object, e as
System.EventArgs)

.......

Private sub Calc
....
RaiseEvent ImDoneCalculating (me, System.EventArgs.Empty)
End Sub

End Class


Public Class MyApp


Private Sub CreateDynControl

Dim MyControl as New DynControl
AddHandler MyControl.ImDoneCalculating , AddressOf Handle_ImDone

End Sub

Private Sub Handle_ImDone (ByVal sender As Object, e as
System.EventArgs)

Dim objValue as Object (or whatever)
objValue = sender.MyCalculations

End Sub

End Class
 
Actually, scratch my answer.

I was in the middle of doing what I told you to do, and just skimmed over
your question, so it seemed right at the time. But thinking about it for a
sec...

1. What exactly are you dynamically creating? How do you 'on the fly'
create a control to do math calcs?
2. My syntax is off on the CreateDynControl, we can get back to that.
3. I skipped over #2 of your explination, so it has nothing to do w/ your
problem.

How are you creating this control? And what exactly do you mean by dynamic?
If your doing math and encryption it seems like your using a precreated
class / .dll and just calling it at run time?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top