G
Guest
Hello All,
I'm dynamically loading a form through reflection. I have this working.
What I'd like to do is implement an interface so that I can cast my instance
to that interface. I want to be able to call methods and pass parameters
normally in the dynamically loaded Form.
Yesterday Nicholas Paldino's suggested this. Btw, thanks Nick! As hard as
I tried without asking further questions, I need a little more help.
Ok, here is a tiny bit of my buggered code. Inside this namespace I added
an interface at the top of the class. I didn't implement the interface in
the MDI. I added the same interface code in the top of the child form (which
gets compiled into a class lib) and in this class lib I actually implement
the interface.
I'm really new with interfaces and reflection, so any and all suggestions
are very welcome.
Thanks very much in advance for your time.
John F
MDI App:
--------------
namespace DynamicLoadMDI
{
public interface IToken
{
string passParams(Object objTemp);
}
public class Form1 : System.Windows.Forms.Form
{
..
..
..
private void btnLoad_Click(object sender, System.EventArgs e)
{
DynamicFormClass objFormToLoad = colAvailableForms[0] as DynamicFormClass;
Assembly assem = Assembly.LoadFrom(objFormToLoad.Location);
Type[] types = assem.GetTypes();
Object genericInstance = assem.CreateInstance(types[1].FullName);
//IToken tok = genericInstance as types[0].GetType(); // I tried this, but
it's always a null reference.
Form tmpForm = genericInstance as Form;
tmpForm.MdiParent=this;
tmpForm.Show();
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.colAvailableForms = new ArrayList();
Object objNewForm = new DynamicFormClass("c:\\testform.dll","Patient
Selection");
colAvailableForms.Add(objNewForm);
}
Child DLL
-----------------
namespace WindowsApplication4
{
interface IToken
{
string passParams(Object objTemp);
}
public class Form1 : System.Windows.Forms.Form, IToken
{
..
..
..
public string passParams(Object objTemp)
{
..
..
..
}
I'm dynamically loading a form through reflection. I have this working.
What I'd like to do is implement an interface so that I can cast my instance
to that interface. I want to be able to call methods and pass parameters
normally in the dynamically loaded Form.
Yesterday Nicholas Paldino's suggested this. Btw, thanks Nick! As hard as
I tried without asking further questions, I need a little more help.
Ok, here is a tiny bit of my buggered code. Inside this namespace I added
an interface at the top of the class. I didn't implement the interface in
the MDI. I added the same interface code in the top of the child form (which
gets compiled into a class lib) and in this class lib I actually implement
the interface.
I'm really new with interfaces and reflection, so any and all suggestions
are very welcome.
Thanks very much in advance for your time.
John F
MDI App:
--------------
namespace DynamicLoadMDI
{
public interface IToken
{
string passParams(Object objTemp);
}
public class Form1 : System.Windows.Forms.Form
{
..
..
..
private void btnLoad_Click(object sender, System.EventArgs e)
{
DynamicFormClass objFormToLoad = colAvailableForms[0] as DynamicFormClass;
Assembly assem = Assembly.LoadFrom(objFormToLoad.Location);
Type[] types = assem.GetTypes();
Object genericInstance = assem.CreateInstance(types[1].FullName);
//IToken tok = genericInstance as types[0].GetType(); // I tried this, but
it's always a null reference.
Form tmpForm = genericInstance as Form;
tmpForm.MdiParent=this;
tmpForm.Show();
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.colAvailableForms = new ArrayList();
Object objNewForm = new DynamicFormClass("c:\\testform.dll","Patient
Selection");
colAvailableForms.Add(objNewForm);
}
Child DLL
-----------------
namespace WindowsApplication4
{
interface IToken
{
string passParams(Object objTemp);
}
public class Form1 : System.Windows.Forms.Form, IToken
{
..
..
..
public string passParams(Object objTemp)
{
..
..
..
}