Instantiate Business Object Dynamically


Author
Message
Tim Dol
Tim Dol
StrataFrame User (434 reputation)StrataFrame User (434 reputation)StrataFrame User (434 reputation)StrataFrame User (434 reputation)StrataFrame User (434 reputation)StrataFrame User (434 reputation)StrataFrame User (434 reputation)StrataFrame User (434 reputation)StrataFrame User (434 reputation)
Group: Forum Members
Posts: 340, Visits: 1.4K
This may be a dumb question but I can't quite get this to work.



I have a string variable containing the fully qualified name of a business object.



Example: Dim var as String = "Avanti.DTS.BusinessObject.CustomersBO"





I want to instantiate the actual business object based on the string value so I can access the field names and lengths etc...



can someone let me know how to do this?



Thanks,

Tim

Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Tim,



I believe you will need to use the Activator.CreateInstance() to make this work, something like this:



Dim var As String = "Avanti.DTS.BusinessObject.CustomersBO"

Dim myBO As Avanti.DTS.BusinessObject.CustomersBO

myBO = CType(Activator.CreateInstance(Type.GetType(var)), Avanti.DTS.BusinessObject.CustomersBO)





If you have a base BO class, then use it in the Dim myBO declaration.

Edhy Rijo

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
I may be misunderstanding the question, but



dim newbo As MicroFour.StrataFrame.Business.BusinessLayer = New Myapp.Business.MyBO




works for me (assuming here myBO is in the myapp.business project)



Same thing works for me.myBO1 if you want the instance.



Need to use fill methods if you need data, but you can check field info etc without it.



Edhy's method, of course, is the solution when you are getting the BO name from a string, but I thought perhaps you weren't doing it dynamically in this case.



Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
(and on rereading your question, Edhy understood your question better than I did.)



Darn I with there were a way to see the question while we are typing an anwer ... or is there ?

Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Charles R Hankey (10/02/2009)
Darn I with there were a way to see the question while we are typing an anwer ... or is there ?





Yes there is, and I have been there before too Smile.



While replying down at the bottom of the page there is header named "Last 10 Post in Descending Order" and on the right side there is a plus sign, just click the plus sign and you will see (guess what?) the last 10 post in descending order Hehe

Edhy Rijo

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Yes! I thought I remembered you asking exactly that question and getting an answer but could remember it. Very cool. Now if they could get Firefox to insert images ...
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
... and of course that should read "could NOT remember it, but there is also not ability to edit one's own posts ... is there?
Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Charles R Hankey (10/04/2009)
...but there is also not ability to edit one's own posts ... is there?




Nope, we all have one shot to make a good impression w00t

Edhy Rijo

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)Advanced StrataFrame User (936 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
So the moral of the story is "Do not drink and post." BigGrin
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Nope, we all have one shot to make a good impression




But just think of it this way...it helps boost your forum count BigGrin



We may have the ability to request this on a per individual basis at some point, but there are some obvious reasons that we prevent this as I am sure you have seen on other posts when we have discussed this before.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search