Using reflection


Author
Message
Ross L. Rooker, Sr.
Ross L. Rooker, Sr.
StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)
Group: Forum Members
Posts: 153, Visits: 462
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?

string strReportName = "ListReportControl";

Control newSample = (Control)Activator.CreateInstance(typeof(ListReportControl));

Reply
Ross L. Rooker, Sr.
Ross L. Rooker, Sr.
StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)StrataFrame User (245 reputation)
Group: Forum Members
Posts: 153, Visits: 462
After converting the VB.NET sample, when run it errors out on the line 9 with Value cannot be null.
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 &LcClassName so that the code would use the value rather than the actual field name.

  1. {
  2.     string LcClassName = "ListReportControl";
  3.     object loObject;
  4.     Type loType;
  5.     //-- Get the type
  6.     loType = Type.GetType(LcClassName);
  7.    
  8.     //-- Create the object
  9.     loObject = Activator.CreateInstance(loType);
  10. }

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