P
Peted
I have 2 samples of code bellow that work fine at the moment
the first routine loads an dll assembley and instantiates the type in
the dll which is always a form, and creates a child form from it.
I need to use latebinfing becasue the dll to be loaded is selected by
the user but is allways a dll with a form class and always
instantiated as a child form.
My problem is how can using this technique pass a reference to the
child form of the parent form in the constructor of the child form in
the dll file. The child form needs to refer back to the parent form
for customs methods to run
I want to pass "this" from the parent form into the child form, but
there does not seem to be anyway to do this using
assembley.createinstance.
Can anyone help please
peted
//loading routine to load child form from dll using latebiding and
reflection
private void loadDeviceInterfaceToSerialPort(int port,String
devicefile)
{
Assembly deviceInterfaceAssembly = null;
// Dynamically load the selected assembly.
deviceInterfaceAssembly = Assembly.LoadFile(devDir +
devicefile);
if (deviceInterfaceAssembly == null)
MessageBox.Show("not loaded");
// Get all types in assembly.
Type[] deviceInterfaceType =
deviceInterfaceAssembly.GetTypes();
ipLink.SetSerialPortDeviceInterface(port,
(Form)deviceInterfaceAssembly.CreateInstance(deviceInterfaceType[0].FullName));
ipLink.GetSerialPortDeviceInterface(port).MdiParent =
this;
ipLink.GetSerialPortDeviceInterface(port).StartPosition =
FormStartPosition.Manual;
ipLink.GetSerialPortDeviceInterface(port).FormBorderStyle =
FormBorderStyle.None;
ipLink.GetSerialPortDeviceInterface(port).Size = new
Size(400, this.ClientRectangle.Height);
ipLink.GetSerialPortDeviceInterface(port).Location = new
Point(540, 0);
ipLink.GetSerialPortDeviceInterface(port).Show();
}
// general form code class in the dll(s) to be loaded.
namespace K108Relay
{
public partial class K108Relay : Form
{
// static IPLinkerator.IPLinkMain host;
public K108Relay()
{
InitializeComponent();
// host.DeviceWrite("1I");
}
private void button1_Click(object sender, EventArgs e)
{
IPLinkMain.staticVar.DeviceWrite("1I");
}
}
}
the first routine loads an dll assembley and instantiates the type in
the dll which is always a form, and creates a child form from it.
I need to use latebinfing becasue the dll to be loaded is selected by
the user but is allways a dll with a form class and always
instantiated as a child form.
My problem is how can using this technique pass a reference to the
child form of the parent form in the constructor of the child form in
the dll file. The child form needs to refer back to the parent form
for customs methods to run
I want to pass "this" from the parent form into the child form, but
there does not seem to be anyway to do this using
assembley.createinstance.
Can anyone help please
peted
//loading routine to load child form from dll using latebiding and
reflection
private void loadDeviceInterfaceToSerialPort(int port,String
devicefile)
{
Assembly deviceInterfaceAssembly = null;
// Dynamically load the selected assembly.
deviceInterfaceAssembly = Assembly.LoadFile(devDir +
devicefile);
if (deviceInterfaceAssembly == null)
MessageBox.Show("not loaded");
// Get all types in assembly.
Type[] deviceInterfaceType =
deviceInterfaceAssembly.GetTypes();
ipLink.SetSerialPortDeviceInterface(port,
(Form)deviceInterfaceAssembly.CreateInstance(deviceInterfaceType[0].FullName));
ipLink.GetSerialPortDeviceInterface(port).MdiParent =
this;
ipLink.GetSerialPortDeviceInterface(port).StartPosition =
FormStartPosition.Manual;
ipLink.GetSerialPortDeviceInterface(port).FormBorderStyle =
FormBorderStyle.None;
ipLink.GetSerialPortDeviceInterface(port).Size = new
Size(400, this.ClientRectangle.Height);
ipLink.GetSerialPortDeviceInterface(port).Location = new
Point(540, 0);
ipLink.GetSerialPortDeviceInterface(port).Show();
}
// general form code class in the dll(s) to be loaded.
namespace K108Relay
{
public partial class K108Relay : Form
{
// static IPLinkerator.IPLinkMain host;
public K108Relay()
{
InitializeComponent();
// host.DeviceWrite("1I");
}
private void button1_Click(object sender, EventArgs e)
{
IPLinkMain.staticVar.DeviceWrite("1I");
}
}
}