matlocker
Messages postés178Date d'inscriptionjeudi 21 février 2002StatutMembreDernière intervention30 juillet 2008
-
13 sept. 2005 à 12:05
SharpMao
Messages postés1024Date d'inscriptionmardi 4 février 2003StatutMembreDernière intervention 7 juin 2010
-
13 sept. 2005 à 15:02
Bonjour a tous,
Je cherchais a créer une instance d'une feuille a partir d'une variable string, et on m'a donné sur ce forum un code qui marche parfaitement. Le voici.
string sForm="NameSpace.Feuille";
System.Reflection.Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
Form f = (Form)ass.CreateInstance(sForm);
f.ShowDialog
Cependant si je possede un constructeur possedant un argument sur la feuille appellé je ne peux passer d'argument avec cette methode. Quelqu'un aurait -il une idée ?
[JScript]
public static function CreateInstance(
[ type] : [ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfsystemtypeclasstopic.htm Type], [ args] : [ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfsystemobjectclasstopic.htm Object][] ) : [ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfsystemobjectclasstopic.htm Object];
Parameters
* type : The type of object to create.
* args : An array of arguments that match in number, order, and type the parameters
of the constructor to invoke. If args is an empty array or a null
reference (Nothing in Visual Basic), the constructor that takes no
parameters (the default constructor) is invoked.
matlocker
Messages postés178Date d'inscriptionjeudi 21 février 2002StatutMembreDernière intervention30 juillet 20081 13 sept. 2005 à 13:56
Dans la liste des surcharge de la methode createinstance j'ai que ca qui contient 2 arguments.
J'ai visual studio 2003 et le frameework 1.1
Mais j'ai pas du tout la signature que tu propose toi.
[JScript]
public function CreateInstance(
[ typeName] : [ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1036/cpref/html/frlrfsystemstringclasstopic.htm String], [ ignoreCase] : [ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1036/cpref/html/frlrfsystembooleanclasstopic.htm Boolean]
) : [ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1036/cpref/html/frlrfsystemobjectclasstopic.htm Object];
Paramètres
* typeName : Propriété [ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1036/cpref/html/frlrfsystemobjectclasstopic.htm Object] représentant le type, dont la culture, les arguments, le binder ainsi que les attributs d'activation ont la valeur une référence null (Nothing dans Visual Basic), et [ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1036/cpref/html/frlrfsystemreflectionbindingflagsclasstopic.htm BindingFlags] a la valeur Public ou Instance ou encore une référence null (Nothing) si typeName est introuvable.
sebmafate
Messages postés4936Date d'inscriptionlundi 17 février 2003StatutMembreDernière intervention14 février 201437 13 sept. 2005 à 14:53
he he... je n'utilise jamais l'instanciation par l'assembly... j'utilise toujours l'objet Activator.
enfin, j'ai développé une appli dernièrement où j'ouvrais des onglets
contenant des usercontrols dynamiquement, et donc le nombre de
paramètres dans le constructeur était variable.