ChildFormDialog error


Author
Message
Chan
Chan
Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)
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
S
StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)
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
S
StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)
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
Chan
Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)Advanced StrataFrame User (713 reputation)
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
S
StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)
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 Smile

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search