|
-
Jun 12th, 2003, 04:17 AM
#1
Thread Starter
Member
call functions dynamic
hi!
is there a way in vb.net to call functions and procedures dynamically at runtime.
background of the question is that i want to fire events at runtime which call a pool of functions. those functions should be defined in a databasetable to keep the application open for further extensions and modifications.
i've experimented a little bit with the codeDOM of .NET but i didn't found what i'm searching for. has anybody an idea how to call functions dynamically at runtime?
best regards
robert
-
Jun 12th, 2003, 08:20 AM
#2
New Member
I have written a probram that calls an dll in this manner. In my case it calls a function with the same name in each of them, what you are wanting to do seems to be an extension of that.
Check into reflection, you might start with this article , I think it will help you accomplish this.
HTH
Brad
-
Jun 12th, 2003, 09:38 AM
#3
Sleep mode
That's what addhandler and withevents created for .
Here's an example , that uses the power of addhandler method : Addhandler can fires one or multiple events or methods at the same time . This is also called delegates. This creates new timer control and you can manage its events at runtime.
VB Code:
Dim WithEvents TimerEvent As Timer
Dim timr As New Timer()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
timr.Interval = 2000
timr.Enabled = True
End Sub
Private Sub FireTimer(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerEvent.Tick
MsgBox("Hey there")
End Sub
Private Sub StopTimer()
timr.Enabled = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
AddHandler timr.Tick, AddressOf FireTimer
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
timr.Enabled = False
End Sub
-
Jun 12th, 2003, 09:57 AM
#4
Thread Starter
Member
the problem with addhandler is that the number of functions/procedures and their names must be known at designtime...
with the dynamic functions and procedures it should also be possible to give the user exits from the standard-software to implement his own code. For ex: the software fires events at points where the user may want to do something other than the standardsoftware do... so he can implement a DLL with a func/proc and adds this info (event + functionname) in the db-table.
but maybe it's better to realize all objects in DLLs and exchange them when necessary. how do you organize your software-projects in order to keep them open?
-
Jun 12th, 2003, 07:25 PM
#5
Addicted Member
reflection is the way to go as far as .NET goes, but an old VB6 throwback could be used for a quick and dirty fix - look into calling procs by using CallByName It accepts the proc name as a string. Bit of a performance hit though!
Code:
Public Sub Test(ByVal str As String)
MessageBox.Show(str)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click
CallByName(Me, "test", CallType.Method, "HELLO")
End Sub
Last edited by powdir; Jun 12th, 2003 at 07:28 PM.
-
Jun 13th, 2003, 07:36 AM
#6
New Member
Originally posted by escape0
how do you organize your software-projects in order to keep them open?
I'm not sure I understand the question. Are you wanting to know how I keep the dlls available at runtime? I don't. I call them once and then dispose of them. I would guess you will need a collection of objects at the class level, but I haven't tried that myself.
If I haven't answered your question let me know and I'll try again.
Brad
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|