Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

StringToObject

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Albert - 09 Sep 2004 13:59 GMT
Imagine a project
I've got two dll's referenced, dll1 and dll2

within some function of my project i want to use a function out of dll1/dll2
Normally you then would put in the function:

Function fncSomeProjFunc as int

   dim myobj as new dll1 (Make the functions of dll1 available inside this
function)
   dim myobj2 as new dll2

   dim sResult as string
   dim sResult2 as string

   sResult = myobj.SomeFunctionwithsResultAsReturnValue
   sResult2 = myobj2.SomeFunctionwithsResultAsReturnValue

   return 1
end function

Now what i want is this

Function fncSomeProjFunc(byval sDllToCall as String) as int
.
..
...
....

end function

sDllToCall is either "dll1" or "dll2" being the NAME of  the object that I
have to declare.
How can I use sDllToCall to declare an object?

If you for example look at it the other way around,

dim myobj as new dll1

msgbox (myobj.toString) would give "dll1"
so maybe there is some function like myobj=sdlltocall.StringToObject or
something like this?

Posted this question elsewhere too, but no one seems to be able to help me
out here.

Thanks for the help
Herfried K. Wagner [MVP] - 09 Sep 2004 14:13 GMT
* "Albert" <albert@informant.nl> scripsit:
> Imagine a project
> I've got two dll's referenced, dll1 and dll2
[quoted text clipped - 30 lines]
> have to declare.
> How can I use sDllToCall to declare an object?

\\\
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)
///

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.