Late binding problem in C# (urgent)
-
This is a C# 2005 Problem: I have an MDIForm and 5 child forms in my project. what i have to do is, during MDI Form's "MdiChildActivate" event I have to set some value to private a variable in my active child form. But when i write a statement like this : this.ActiveMdiChild.childVariableMode="0"; I get an error-"No defination For childVariableMode found in activemdichild". In vb.net i can do this by: dim a as object a=me.ActiveMdiChild a.childVariableMode="0" But i C# if i do same as VB.NET i get the same error, please solve my problem.I am in very hurry, my whole project is depended on this. Thanks in Advance. Sheel Sheel Gohe Sheel Gohe
-
This is a C# 2005 Problem: I have an MDIForm and 5 child forms in my project. what i have to do is, during MDI Form's "MdiChildActivate" event I have to set some value to private a variable in my active child form. But when i write a statement like this : this.ActiveMdiChild.childVariableMode="0"; I get an error-"No defination For childVariableMode found in activemdichild". In vb.net i can do this by: dim a as object a=me.ActiveMdiChild a.childVariableMode="0" But i C# if i do same as VB.NET i get the same error, please solve my problem.I am in very hurry, my whole project is depended on this. Thanks in Advance. Sheel Sheel Gohe Sheel Gohe
The best way is to cast ActiveMdiChild down to the class which has the childVariableMode variable. If ActiveMdiChild can be one of several classes, where only some have the variable defined, then your best bet is to declare a base class from which all MDI children derive from and place the childVariableMode variable in the base class. A quick hack would be to use reflection to do what you want. Simply query for the variables in the object using the variable name ("childVariableMode") and then set the value of the variable. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
This is a C# 2005 Problem: I have an MDIForm and 5 child forms in my project. what i have to do is, during MDI Form's "MdiChildActivate" event I have to set some value to private a variable in my active child form. But when i write a statement like this : this.ActiveMdiChild.childVariableMode="0"; I get an error-"No defination For childVariableMode found in activemdichild". In vb.net i can do this by: dim a as object a=me.ActiveMdiChild a.childVariableMode="0" But i C# if i do same as VB.NET i get the same error, please solve my problem.I am in very hurry, my whole project is depended on this. Thanks in Advance. Sheel Sheel Gohe Sheel Gohe
The ActiveMdiChild property returns a Form object which contains no definition for childVariableMode. To access this variable you have to cast the returned form object to one of your child form types. Because you don't know which one is currently the active child, you need a way to treat all child form types equally. One possibility is to define a common base type for all child forms which contains the childVariableMode property and then cast the return value of ActiveMdiChild property to this type. Another way is to define an interface with the childVariableMode which then gets implemented by all child forms and in this case cast the return value of ActiveMdiChild property to interface type.