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
|
|
|
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
|
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.
|
|
|
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.
|
|
|
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
|
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 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
|
|
|
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()?
|
|
|
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
|
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")
|
|
|