RE: Object Name

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Carl (Carl_at_discussions.microsoft.com)
Date: 07/09/04


Date: Fri, 9 Jul 2004 10:02:01 -0700

The code I found on this board does not work, any idea why ?

It returns the error,

An unhandled exception of type 'System.NullReferenceException' occurred in System.Windows.Forms.dll

at line ,

if(f.GetValue(((Control)SourceControl).Parent).Equals(SourceControl))
        return f.Name;

The object I pass to it is a textbox from a pageframe.

-------------------------------------------------------------------------------------------
public static string GetControlName(object SourceControl)
{
FieldInfo[] fi = ((Control)SourceControl).Parent.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.Public | BindingFlags.IgnoreCase);

foreach(FieldInfo f in fi)
{
        if(f.GetValue(((Control)SourceControl).Parent).Equals(SourceControl))
        return f.Name;
}

return null;
}

"Carl" wrote:

> See this link for a fix.
>
> http://blog.opennetcf.org/ctacke/PermaLink.aspx/64c28b10-d3a8-4c6b-b11a-2ae2de4bdaf1
>
> "Carl" wrote:
>
> > Is there a way in the PPC2002 and Compact Frame Work to figure out the name of an object pass to a function?
> >
> > It seam there is no name properties.
> >
> > Example :
> > -----------------------------------------------------------------------------------------------
> > public void SetDataInputField(TabPage ObjTabReceive)
> > {
> > foreach(Object myOBJ in ObjTabReceive.Controls)
> > {
> > if (myOBJ is System.Windows.Forms.TextBox)
> > {
> > TextBox fieldToValidate = (TextBox) myOBJ;
> > if(fieldToValidate.Name = "txtHours")
> > {
> > // do some treatments
> > }
> >



Relevant Pages

  • im still here ...
    ... public void paintComponent{ ... public static String setAlarm(String theAlarm,String theTime){ ...
    (comp.lang.java.help)
  • Re: JTable help
    ... interActiveJatable and the resultObject: ... public void setClassCode{ ... public static final int CLASS_INDEX = 1; ...
    (comp.lang.java.help)
  • Re: top-post...
    ... > public void keyPressed ... > public static String reverse(String s, ... > String s, boolean lines, boolean letters) ...
    (comp.lang.java.programmer)
  • Re: Array of Objects
    ... > public static String y; ... public void pusht ... they have class scope rather than instance scope. ...
    (comp.lang.java.programmer)