Andria Jensen
|
|
Group: Forum Members
Posts: 336,
Visits: 497
|
I have a ChildFormDialog control on a form, and have set up the ChildForm and BO Translations for it. The child form is coming from a dll and is an inherited form. In my code I call ChildFormBank.ShowDialog() and get the attached error message every time. I have included the stack trace for more info. 11/2/2006 9:35:32 AM Source: mscorlib Message: Value cannot be null. Parameter name: type Stack: at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args) at MicroFour.StrataFrame.UI.Windows.Forms.ChildFormDialog.CreateForm(Object[] Arguments) at MicroFour.StrataFrame.UI.Windows.Forms.ChildFormDialog.ShowDialog(Object[] Arguments) at MicroFour.StrataFrame.UI.Windows.Forms.ChildFormDialog.ShowDialog() at BBS.GUI.frmClientInfo.MaintBankRel_AfterButtonClick() in C:\FactorSoftV3\GUI\ClientInfo\frmClientInfo.vb:line 205 at BBS.GUI.BaseControls.MaintStrip.button_Click(Object sender, EventArgs e) at System.Windows.Forms.Control.OnClick(EventArgs e) at DevExpress.XtraEditors.BaseButton.OnClick(EventArgs e) at DevExpress.XtraEditors.BaseButton.OnMouseUp(MouseEventArgs e) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi, I am facing the same problem. I tried the code below.
//Workign OK
Payment.UI.Windows.Forms.PaymentForm loForm = new PaymentForm(new object[]
{ JK.Payment.Enums.TxnType.Sale, salesBO.SaleNo, salesBO.Total });
loForm.ShowDialog();
loForm.Dispose();
//Workign OK
loForm = (PaymentForm)Activator.CreateInstance(Type.GetType("JK.Payment.UI.Windows.Forms.PaymentForm"));
loForm.ShowDialog();
loForm.Dispose();
//NOT Workign OK
loForm = (PaymentForm) Activator.CreateInstance(Type.GetType("JK.Payment.UI.Windows.Forms.PaymentForm"),
new object[]
{
JK.Payment.Enums.TxnType.Sale, salesBO.SaleNo,
salesBO.Total
});
loForm.ShowDialog();
loForm.Dispose();
Any advice? Thank you
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
What sort of error do you get from the second call to Activator.CreateInstance (the one where you pass the starting parameters)? Is is a MissingMethodException? Or a TypeLoadException? Or something else?
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi,
I hit error
Constructor on type 'JK.Payment.UI.Windows.Forms.PaymentForm' not found.
However, as the code I posted, it works if I use the code below
//Workign OK
Payment.UI.Windows.Forms.PaymentForm loForm = new PaymentForm(new object[]
{ JK.Payment.Enums.TxnType.Sale, salesBO.SaleNo, salesBO.Total });
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
Aha, in the code that you posted, you're expecting one parameter that it an object[]. When you call the Activator.CreateInstance, it's excpecting you to pass all of the parameters in an object[], so, you have to put your object[] into the object[] that the CreateInstance method is excpecting. Like this: loForm = (PaymentForm) Activator.CreateInstance(Type.GetType("JK.Payment.UI.Windows.Forms.PaymentForm"), new object[] { new object[] { JK.Payment.Enums.TxnType.Sale, salesBO.SaleNo, salesBO.Total } } ); The object[] that the CreateInstance is expecting is an array of all of the parameters, so the one that you create only needs to contain one item. But, since that one item is itself an array of object, you'll have to put your parameter object[] inside another object[] to pass to the CreateInstance() method.
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
If you didn't want to pass all of your parameters as an object[], then you'll want to change your constructor so that it does not expect an object, but just 3 regular parameters. Then, you can remove the outer object from the CreateInstance() call.
|
|
|
Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Ben Chase (08/28/2007) If you didn't want to pass all of your parameters as an object[], Hi, Thank you tip. I will try it out later. then you'll want to change your constructor so that it does not expect an object, but just 3 regular parameters. Then, you can remove the outer object from the CreateInstance() call. I don't think ChildFormDialog support this, doesn it? Thank you
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
Yep, the ChildFormDialog is designed to work like that. If your form is like this: public class Form1 : System.Windows.Forms.Form { public Form1(string param1, string param2, string param3) { } } Then you're call to childFormDialog.ShowDialog() will look like this: childFormDialog.ShowDialog("param1", "param2", "param3"); The signature of the method is like this: public DialogResult ShowDialog(params object[] parameters) {} The keyword being the "params" at the beginning. It means that you can add as many parameters as you want and separate them with commas and the compiler will pass them all as one big object array. It's smart like that
|
|
|