|
-
Nov 23rd, 2005, 03:19 PM
#1
Thread Starter
Addicted Member
Converting string name of an object to the actual object
Is it possible to dim an object as a evaluation of a string variable.
VB Code:
Friend gobjSalesRecord As SageDataObject100.SalesRecord
Public Sub New(ByVal strSDODataObjectName As String)
Dim objSDODataObject As Object
objSDODataObject = strSDODataObjectName
......
End Sub
Where strSDODataObjectName = "gobjSalesRecord"
I want to convert that string name of the object to the actual Object and pass that, ie make objSDODataObject = gobjSalesRecord
-
Nov 23rd, 2005, 03:28 PM
#2
Re: Converting string name of an object to the actual object
Why not just pass the entire object into the sub?... (byval DataObject as SageDataObject100.SalesRecord)
-
Nov 23rd, 2005, 03:46 PM
#3
Thread Starter
Addicted Member
Re: Converting string name of an object to the actual object
Because I don't know which object I want to use until run time and the calling program does not know anything about SageDataObject100.SalesRecord .....
Anyway fixed it ... just needed to change this line
objSDODataObject = strSDODataObjectName
to
objSDODataObject = CObj(strSDODataObjectName)
-
Nov 23rd, 2005, 04:21 PM
#4
Re: Converting string name of an object to the actual object
Um, no. All that does is cast your String as an Object and assign it to that variable. It absolutely DOES NOT get a reference to an object that is refered to by a variable of that name. strSDODataObjectName is a string variable and the value it contains has no relationship whatsoever to any other variable whose name is the same as that value. If you want to get a member variable from a name in a string then you need to use Reflection.
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
|