﻿<?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 reflection</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Sun, 05 Apr 2026 18:51:57 GMT</lastBuildDate><ttl>20</ttl><item><title>Using reflection</title><link>http://forum.strataframe.net/FindPost17273.aspx</link><description>I have a reference in my project to a Sharpshooter Report. When I instantiate it, using the name of the the control "ListReportControl" in the second line below works, but I need to change that line to be able to specify a string variable that has the value of the report control. How would the line need to be changed to allow this?&lt;/P&gt;&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&lt;FONT color=#000000&gt; strReportName = &lt;/FONT&gt;&lt;SPAN style="COLOR: #a31515"&gt;"ListReportControl"&lt;/SPAN&gt;&lt;FONT color=#000000&gt;;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT color=#000000&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Control&lt;/SPAN&gt;&lt;FONT color=#000000&gt; newSample = (&lt;/FONT&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Control&lt;/SPAN&gt;&lt;FONT color=#000000&gt;)&lt;/FONT&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Activator&lt;/SPAN&gt;&lt;FONT color=#000000&gt;.CreateInstance(&lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;typeof&lt;/SPAN&gt;&lt;FONT color=#000000&gt;(&lt;/FONT&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ListReportControl&lt;/SPAN&gt;&lt;FONT color=#000000&gt;));&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;</description><pubDate>Tue, 24 Jun 2008 12:33:05 GMT</pubDate><dc:creator>Ross L. Rooker, Sr.</dc:creator></item><item><title>RE: Using reflection</title><link>http://forum.strataframe.net/FindPost17297.aspx</link><description>Thanks, I believe this works.</description><pubDate>Tue, 24 Jun 2008 12:33:05 GMT</pubDate><dc:creator>Ross L. Rooker, Sr.</dc:creator></item><item><title>RE: Using reflection</title><link>http://forum.strataframe.net/FindPost17296.aspx</link><description>I just red a forum post at [url] http://forums.devx.com/archive/index.php/t-55448.html [/url]&lt;br&gt;
basically the string needs to contain both the Assembly name and the class name, separated with comma. Like this:&lt;br&gt;
&lt;br&gt;
string lcClassName = "YourAssemblyName, YourReportClassName"&lt;br&gt;
&lt;br&gt;
then the rest of the code should work. I haven't tested it.&lt;br&gt;
Good luck ;)</description><pubDate>Tue, 24 Jun 2008 11:56:55 GMT</pubDate><dc:creator>Guillermo Vilas</dc:creator></item><item><title>RE: Using reflection</title><link>http://forum.strataframe.net/FindPost17294.aspx</link><description>{ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string LcClassName = "ListReportControl";&amp;nbsp; //-- The type will be 'string' in this case&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; object loObject; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Type loType; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //-- Get the type &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; loType = Type.GetType(LcClassName); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //-- Create the object &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; loObject = Activator.CreateInstance(loType); //-- The activator won´t be able to create an instace from a string type&lt;BR&gt;} &lt;/P&gt;&lt;P&gt;Yes, this is the dilema which I am trying to solve whether with the above code or from the code at the top of this thread. Basically I need to know the .net syntax to have the Type.GetType() get the type of the control which is represented by the string LcClassName which in the sample above would be "ListReportControl". ListReportControl is a control. One of about 600 report controls. Each control represents a Sharpshooter report. Initially all the Reports are in SQL, then loaded into a TreeView on the left side of a "viewer" form. The user selects a report such as one "ListReportControl". I then need to instantiate that control into a "commonControl" for the global report viewer which appears in a host panel to the right of the treeview. Other than the treeview which comes from a SQL table, I do not want to hardcode all 600 possible report controls into code. Hence when the user clicks a report in the treeview, after the &lt;FONT size=2&gt;treeView_AfterSelect event is triggered. At that point I have a string value (LcClassName) which has the name of the report control such as "ListReportControl". &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;Basically inserting this code works perfect with the issue that the Report Name control "ListReportControl" is coded to make it work. I believe there is a way with "reflection" to allow me to specify a string such as LcClassName and the code would then take the "value" of the string and return the "type" of value of the string which is "ListReportControl".&lt;/FONT&gt;&lt;/P&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;&lt;P&gt;Control&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; newSample = (&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Control&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;)&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Activator&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;.CreateInstance(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;typeof&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;ListReportControl&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2&gt;&lt;FONT size=2&gt;&lt;P&gt;Text = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Preparing data for report..."&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;&lt;P&gt;(newSample &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;IReportControl&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;).PrepareData();&lt;/P&gt;&lt;P&gt;Text = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Rendering..."&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;&lt;P&gt;activeReportSlot = (newSample &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;IReportControl&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;).GetReportSlot();&lt;/P&gt;&lt;P&gt;RenderReport();&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;newSample.Dock = &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;DockStyle&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.Fill;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;&lt;P&gt;Control&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; c = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; (hostPanel.Controls.Count != 0)&lt;/P&gt;&lt;P&gt;c = hostPanel.Controls[0];&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; (c != newSample)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; (c != &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;hostPanel.Controls.Remove(c);&lt;/P&gt;&lt;P&gt;hostPanel.Controls.Add(newSample);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Tue, 24 Jun 2008 11:00:00 GMT</pubDate><dc:creator>Ross L. Rooker, Sr.</dc:creator></item><item><title>RE: Using reflection</title><link>http://forum.strataframe.net/FindPost17286.aspx</link><description>Hi Ross,&lt;P&gt;I think the problem is that you´re asking to create an instance of type string as described bellow&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;{ &lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string LcClassName = "ListReportControl";&amp;nbsp; //-- The type will be 'string' in this case&lt;LI&gt;&amp;nbsp; &amp;nbsp; &lt;SPAN class=keyword&gt;object&lt;/SPAN&gt; loObject; &lt;LI&gt;&amp;nbsp; &amp;nbsp; &lt;SPAN class=keyword&gt;&lt;A href="http://labs.developerfusion.co.uk/SourceViewer/search/SSCLI/Type/"&gt;Type&lt;/A&gt;&lt;/SPAN&gt; loType; &lt;LI&gt;&amp;nbsp; &amp;nbsp; &lt;SPAN class=comment&gt;//-- Get the type&lt;/SPAN&gt; &lt;LI&gt;&amp;nbsp; &amp;nbsp; loType = Type.GetType(LcClassName); &lt;LI&gt;&amp;nbsp; &amp;nbsp; &lt;LI&gt;&amp;nbsp; &amp;nbsp; &lt;SPAN class=comment&gt;//-- Create the object&lt;/SPAN&gt; &lt;LI&gt;&amp;nbsp; &amp;nbsp; loObject = Activator.CreateInstance(loType); //-- The activator won´t be able to create an instace from a string type&lt;LI&gt;} &lt;/LI&gt;&lt;/OL&gt;</description><pubDate>Tue, 24 Jun 2008 09:38:26 GMT</pubDate><dc:creator>Guillermo Vilas</dc:creator></item><item><title>RE: Using reflection</title><link>http://forum.strataframe.net/FindPost17282.aspx</link><description>After converting the VB.NET sample, when run it errors out on the line 9 with Value cannot be null.&lt;BR&gt;Parameter name: type. The problem I believe is the the "type" of the variable LcClassName is "string". The value of LcClassName which is "ListReportControl" is a type of "control". I know in FoxPro you could specify the field as &amp;amp;LcClassName so that the code would use the value rather than the actual field name.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;{ &lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string LcClassName = "ListReportControl";&lt;LI&gt;&amp;nbsp; &amp;nbsp; &lt;SPAN class=keyword&gt;object&lt;/SPAN&gt; loObject; &lt;LI&gt;&amp;nbsp; &amp;nbsp; &lt;SPAN class=keyword&gt;&lt;A href="http://labs.developerfusion.co.uk/SourceViewer/search/SSCLI/Type/"&gt;Type&lt;/A&gt;&lt;/SPAN&gt; loType; &lt;LI&gt;&amp;nbsp; &amp;nbsp; &lt;SPAN class=comment&gt;//-- Get the type&lt;/SPAN&gt; &lt;LI&gt;&amp;nbsp; &amp;nbsp; loType = Type.GetType(LcClassName); &lt;LI&gt;&amp;nbsp; &amp;nbsp; &lt;LI&gt;&amp;nbsp; &amp;nbsp; &lt;SPAN class=comment&gt;//-- Create the object&lt;/SPAN&gt; &lt;LI&gt;&amp;nbsp; &amp;nbsp; loObject = Activator.CreateInstance(loType); &lt;LI&gt;} &lt;/LI&gt;&lt;/OL&gt;</description><pubDate>Tue, 24 Jun 2008 08:31:51 GMT</pubDate><dc:creator>Ross L. Rooker, Sr.</dc:creator></item><item><title>RE: Using reflection</title><link>http://forum.strataframe.net/FindPost17278.aspx</link><description>Yup...good answer, Paul. :)</description><pubDate>Tue, 24 Jun 2008 08:15:33 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Using reflection</title><link>http://forum.strataframe.net/FindPost17275.aspx</link><description>you just need to call Gettype with the classname and pass that to createinstance.&lt;/P&gt;&lt;P&gt;Dim loObject As Object&lt;BR&gt;Dim loType As Type&lt;BR&gt;&amp;nbsp;&amp;nbsp;'-- Get the type&lt;BR&gt;&amp;nbsp;loType = Type.GetType(LcClassName)&lt;/P&gt;&lt;P&gt;&amp;nbsp;'-- Create the object&lt;BR&gt;&amp;nbsp;loObject = Activator.CreateInstance(loType)&lt;/P&gt;&lt;P&gt;Paul</description><pubDate>Tue, 24 Jun 2008 07:55:24 GMT</pubDate><dc:creator>Paul Chase</dc:creator></item></channel></rss>