﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » Using property as a string to resolve at runtime to an object reference</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Fri, 29 May 2026 14:14:48 GMT</lastBuildDate><ttl>20</ttl><item><title>Using property as a string to resolve at runtime to an object reference</title><link>http://forum.strataframe.net/FindPost22125.aspx</link><description>I have a piece of code in a form :&lt;br&gt;
&lt;br&gt;
[codesnippet]&lt;br&gt;
    Private Sub lvSelections_ListPopulating(ByVal e As MicroFour.StrataFrame.UI.ListPopulatingEventArgs) _&lt;br&gt;
                    Handles lvSelections.ListPopulating&lt;br&gt;
&lt;br&gt;
                    e.Parameters(0).Value = Me.Vr_PolicyHolderListBO1&lt;br&gt;
                    e.Parameters(1).Value = _&lt;br&gt;
                    MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable&lt;br&gt;
    End Sub&lt;br&gt;
&lt;br&gt;
    Private Sub btnViewReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _&lt;br&gt;
                    Handles btnViewReport.Click&lt;br&gt;
                    UI.FormManager.OpenReport(GetType(InsurtecPH.Reporting.Forms.PolicyHolderListReportForm), _&lt;br&gt;
                    New Object() {Me.Vr_PolicyHolderListBO1}, False)&lt;br&gt;
    End Sub[/codesnippet]&lt;br&gt;
&lt;br&gt;
I want to have properties that can be set at design time that at run-time will result in the BO references being set to the object referred to by the property and ReportForm likewise.  &lt;br&gt;
&lt;br&gt;
Since the form is in a different assembly and for simplicity sake it seems two string properties would do the trick but I am open to suggestions.  Obviously I want to make this generic so that in a subclass I can set the properties and have the same behavior except for the the BO and form used.  Struggling with syntax.&lt;br&gt;
&lt;br&gt;
Suggestions appreciated. TIA&lt;br&gt;
&lt;br&gt;</description><pubDate>Fri, 27 Feb 2009 14:12:06 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Using property as a string to resolve at runtime to an object reference</title><link>http://forum.strataframe.net/FindPost22128.aspx</link><description>There is an method in the framework that takes the [b]full[/b] name of a type and returns its type (yep, I finally found it!):&lt;br&gt;
&lt;br&gt;
[codesnippet]Microfour.StrataFrame.Tools.Common.GetTypeFromReferencedAssemblies(typeName As String)[/codesnippet]&lt;br&gt;
&lt;br&gt;
So, if you had a property, say [i]ReportForm[/i], which was a string, then you could redo your code like:&lt;br&gt;
&lt;br&gt;
[codesnippet]'-- Get the System.Type of the report form&lt;br&gt;
Dim reportFormType As System.Type&lt;br&gt;
reportFormType = Common.GetTypeFromReferencedAssemblies(Me.ReportForm)&lt;br&gt;
UI.FormManager.OpenReport(reportFormType, New Object() {Me.Vr_PolicyHolderListBO1}, False)[/codesnippet]&lt;br&gt;
&lt;br&gt;
It would be harder to do this generically with the BO, as you passing an instance, not a type.  So, you'd somehow need to actually get an instance of the correct type.  Just knowing the name of the type wouldn't be helpful, as the BO is being passed to the constructor of the report form, and has the data that will actually drive the report. Thus it would need not only be instantiated, but also filled.&lt;br&gt;
&lt;br&gt;
However, you could provide a generic BusinessObject property of the more general type BusinessLayer. This would then get set somehow with the actual BO that contained the data. The code would then become:&lt;br&gt;
&lt;br&gt;
[codesnippet]'-- Get the System.Type of the report form&lt;br&gt;
Dim reportFormType As System.Type&lt;br&gt;
reportFormType = Common.GetTypeFromReferencedAssemblies(Me.ReportForm)&lt;br&gt;
UI.FormManager.OpenReport(reportFormType, New Object() {Me.BusinessObject}, False)[/codesnippet]&lt;br&gt;
&lt;br&gt;
Hope that gets you moving some more! :D</description><pubDate>Fri, 27 Feb 2009 14:12:06 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item></channel></rss>