Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 121205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:56:00+00:00 2026-05-11T03:56:00+00:00

I’ve been using the factory model to create child forms to add to a

  • 0

I’ve been using the factory model to create child forms to add to a MDI form. This is the code I’ve been using:

    /// <summary>     /// This uses the Factory Model to create the child node and then add it to the MDI Parent (this)     /// </summary>     /// <param name='childName'>String class name of the child, i.e. RentalEase.PropertyGrid must extend Form or SingleInstance</param>     /// <param name='singleInstance'>bool If this class is to be a single instance and restricted to only on instance. Must extend SingleInstance</param>     public void createChild(string childName, bool singleInstance) {         if (singleInstance) {             try {                 BaseAndSingleInstanceForm f = BaseAndSingleInstanceForm.getInstanceByType(this, Type.GetType(childName));                     f.MdiParent = this;                     f.Show();                     f.BringToFront();                     this.Refresh();             } catch (Exception ex) {                 MessageBox.Show('Could not create child: ' + ex.ToString());             }         } else {             try {                 object o = Activator.CreateInstance(Type.GetType(childName));                 if (o is Form) {                     Form f = (Form)o;                     f.MdiParent = this;                     f.Show();                     f.BringToFront();                     this.Refresh();                 } else {                     throw new ArgumentException('Invalid Class');                 }             } catch (Exception ex) {                 MessageBox.Show('Could not create child: ' + ex.ToString());             }         }     } 

However, a situation has arose that I have to add an integer parameter to the constructor of a specific form. How can I change this and make it reflect it while still maintaining the pattern at it’s current ease of use (or nearly).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:56:01+00:00Added an answer on May 11, 2026 at 3:56 am

    You could add a Object[] parameter to the method that would represent the parameters to the constructor of the object you wish to instantiate. Then when you call Activator.CreateInstance you could pass that array in and Activator would do its best to find a constructor on the type you specified that matches the types in the Object array.

    Here is a much simplified example of what I mean:

    using System;  class Program {     static void Main()     {         Foo foo = (Foo)create('Foo', new Object[] { });         Bar bar = (Bar)create('Bar', new Object[] { 'hello bar' });         Baz baz = (Baz)create('Baz', new Object[] { 2, 'hello baz' });     }      static Object create(String typeName, Object[] parameters)     {         return Activator.CreateInstance(Type.GetType(typeName), parameters);     }    }  class Foo {     public Foo() { } }  class Bar {     public Bar(String param1) { } }  class Baz {     public Baz(Int32 param1, String param2) { } } 

    We have three types that all have different constructors – if the caller is responsible for sending in the type name then they will also be responsible for supplying an array of Objects that will satisfy a non-default constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.