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)
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
There's nothing magic done here...we just call an Activator.CreateInstance and pass the type that you specify for the child dialog form. Once thing that tends to cause an error is when the ChildForm is expecting a parameter in the New and you do not provide that parm in the ShowDialog: MyChildDialogControl.ShowDialog(YourParms)
|
|
|
Andria Jensen
|
|
Group: Forum Members
Posts: 336,
Visits: 497
|
I understand what you're saying, but what doesn't make sense to me here is that I can instantiate the form which I am using as the child and call a show on it, without using the ChildFormDialog control and it shows fine. There must be something that acts differently when using this control. Maybe something to do with the way the translations? I'm just guessing here...not sure how to go about debugging this.
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
First see if you can just call Activator.CreateInstance on it. Dim loForm As System.WIndows.Forms.Form loForm = CType(Activator.CreateInstance(GetType(MyFormType)), System.WIndows.Forms.Form) loForm.SHowDialog()
|
|
|
Andria Jensen
|
|
Group: Forum Members
Posts: 336,
Visits: 497
|
OK, I sort of figured it out. Not sure what this means and pretty sure it's not supposed to work this way. I have a local form which I set as the ChildForm, and this works fine...no problems. This works without creating an instance of the local form. When I try to set the ChildForm to a form coming from a referenced DLL it gives me the error. However, if I create an instance of the form (with any name) it works fine. So basically if it's a form from the same project no instance is needed, but if it's coming from a referenced dll then you must create an instance first. This code works for forms in same project: ChildFormDialog1.ShowDialog() This code works for forms from dlls where ChildFormDialog1 has ChildForm=frmChildForm: Dim ChildFormDLL as New frmChildForm ChildFormDialog1.ShowDialog
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
Actually, you can use a referenced form from a DLL. But the problem may be that the full name (i.e. YourNameSpace.YourForm) may not be valid through the reference that is being specified. You may need to load the assembly. For example, open your designer file and go to the ChildForm property in the designer file. You will see the name of the form like something I mentioned above. See if your activator.CreateInstance works with the full name rather than the type: Activator.CreateInstance("YourNameSpace.YourFormName")
|
|
|
Andria Jensen
|
|
Group: Forum Members
Posts: 336,
Visits: 497
|
I checked the designer code and it looks like it is already using the fully qualified name for the form, including the namespace BBS.GUI. This is the code from the designer: BusinessObjectTranslationItem3.DestinationBusinessObject = "frmCliBroker.CliBrokerBO" BusinessObjectTranslationItem3.SourceBusinessObject = "frmClientInfo.CliBrokerBO" Me.ChildFormBrokerRel.BusinessObjectTranslations.AddRange(New MicroFour.StrataFrame.UI.Windows.Forms.BusinessObjectTranslationItem() {BusinessObjectTranslationItem3}) Me.ChildFormBrokerRel.ChildForm = "BBS.GUI.frmCliBroker" Me.ChildFormBrokerRel.ParentForm = Me
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
Does the fully qualified name work in a test scenario when you manually call the Activator.CreateInstance()?
|
|
|
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?
|
|
|