PC Review


Reply
Thread Tools Rate Thread

Dynamic call .net object

 
 
Tom
Guest
Posts: n/a
 
      25th Oct 2004
Can I dynamic call vb.net object

such like vb6 as sample

dim A as object
set a = createobject("myobject.test")
a.open()

now mypbject.test is create vb.net . How can I dynamic call without use
reference method.

Thanks


 
Reply With Quote
 
 
 
 
Matt S
Guest
Posts: n/a
 
      25th Oct 2004
Have a look at:

Activator.CreateInstance

Hope this helps

Matt.

"Tom" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Can I dynamic call vb.net object
>
> such like vb6 as sample
>
> dim A as object
> set a = createobject("myobject.test")
> a.open()
>
> now mypbject.test is create vb.net . How can I dynamic call without use
> reference method.
>
> Thanks
>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      25th Oct 2004
"Tom" <(E-Mail Removed)> schrieb:
> now mypbject.test is create vb.net . How can I dynamic call
> without use reference method.


\\\
Private Function CreateClassByName( _
ByVal PartialAssemblyName As String, _
ByVal QualifiedClassName As String _
) As Object
Return _
Activator.CreateInstance( _
[Assembly].LoadWithPartialName( _
PartialAssemblyName _
).GetType(QualifiedClassName) _
)
End Function
///

Usage:

\\\
Dim c As Control = _
DirectCast( _
CreateClassByName( _
"System.Windows.Forms", _
"System.Windows.Forms.Button" _
), _
Control _
)
With c
.Location = New Point(10, 10)
.Size = New Size(80, 26)
.Text = "Hello World"
End With
Me.Controls.Add(c)
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


 
Reply With Quote
 
Tom
Guest
Posts: n/a
 
      26th Oct 2004
Hi All
Thanks

However, I want to create the vbproject . One vb project (type is windows
application .exe) dynamic call another vbproject (class libary .dll) . while
windows application project do not need add reference "class libary ".
I use VB6 as example:
I create standard exe name "myApp" with the form "frmtest" . In this
frmtest. I create the button name "cmdBtn"
Meanwhile I create activex dll name "classLibs" with the class Name
"myClass". In this myClass. I create the method "HelloWorld".


In Vb6 syntax. I just do the follow :

Private Sub Command1_Click()
Dim O as object
set O = createobject("classLibs.myClass")
O.HelloWorld
End Sub

Now , Both myApp and classLibs is a .net component . I don't need convert
them into activex com. Just want to dynamic call.
How you help me above this ?

Thanks and many thanks




"Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> ¦b¶l¥ó
news:(E-Mail Removed) ¤¤¼¶¼g...
> "Tom" <(E-Mail Removed)> schrieb:
> > now mypbject.test is create vb.net . How can I dynamic call
> > without use reference method.

>
> \\\
> Private Function CreateClassByName( _
> ByVal PartialAssemblyName As String, _
> ByVal QualifiedClassName As String _
> ) As Object
> Return _
> Activator.CreateInstance( _
> [Assembly].LoadWithPartialName( _
> PartialAssemblyName _
> ).GetType(QualifiedClassName) _
> )
> End Function
> ///
>
> Usage:
>
> \\\
> Dim c As Control = _
> DirectCast( _
> CreateClassByName( _
> "System.Windows.Forms", _
> "System.Windows.Forms.Button" _
> ), _
> Control _
> )
> With c
> .Location = New Point(10, 10)
> .Size = New Size(80, 26)
> .Text = "Hello World"
> End With
> Me.Controls.Add(c)
> ///
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fw: Referenced COM Object Versus Dynamic Load Of COM Object Claire Microsoft C# .NET 2 9th Oct 2008 03:17 AM
Dynamic call object in C# Michael Microsoft C# .NET 3 29th Sep 2005 06:29 PM
How to call a dynamic function from Dynamic Menu? tsair Microsoft C# .NET 1 14th Apr 2005 09:20 AM
Object reference not set to an instance of an object error during netapi32 call Kurt Van Campenhout Microsoft VB .NET 5 19th Nov 2003 11:46 PM
Object reference not set to an instance of an object error during netapi32 call Kurt Van Campenhout Microsoft VB .NET 1 18th Nov 2003 09:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:13 PM.