473,718 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't find object reference

Okay here are four classes for a pocket pc program: Input, fpositional,
ComboBoxArray and TextBoxArray. The "input" class is the form. I use the
fpositional class to handle most of the functions for the objects on the
form, in addition the The objects are created in the fpositional class and
affixed to the Input form through the fpositional constructor which takes the
form as an argument. The ComboBox and TextBox Array classes hold the
respective objects. I want the objects to interact with eachother through
their
event handlers. This example tries to manipulate the Back and Fore color of
the two object types. (Note: if you don't have a PocketPC the PPC Emulator
will not change the color of the ComboBox.) You can add a MessageBox in the
updateObjectsCo lors() function in fpositional to report other property
settings.
You will get errors with the updateObjectsCo lors() function in the Array
classes. It asks for an object reference but I can't seem to find the
reference. The program will run if you comment out the updateObjectsCo lors()
used in the event handlers of the Array Classes. I hope someone can figure
this out.

Here are the 4 classes:

****Input Class****
using System;
using System.Drawing;
using System.Collecti ons;
using System.Windows. Forms;
using System.Data;

namespace PocketFSR
{
public class Input : System.Windows. Forms.Form
{
private System.Windows. Forms.Button button1;
private System.Windows. Forms.Button button2;
private System.Windows. Forms.MainMenu InputMenu;
fpositional position;

public Input(){Initial izeComponent(); }

protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code

private void InitializeCompo nent()
{
this.InputMenu = new System.Windows. Forms.MainMenu( );
this.button1 = new System.Windows. Forms.Button();
this.button2 = new System.Windows. Forms.Button();
//
// button1
//
this.button1.Lo cation = new System.Drawing. Point(48, 208);
this.button1.Si ze = new System.Drawing. Size(64, 32);
this.button1.Te xt = "Add";
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
//
// button2
//
this.button2.Lo cation = new System.Drawing. Point(120, 208);
this.button2.Si ze = new System.Drawing. Size(72, 32);
this.button2.Te xt = "Remove";
this.button2.Cl ick += new System.EventHan dler(this.butto n2_Click);
//
// Input
//
this.Controls.A dd(this.button2 );
this.Controls.A dd(this.button1 );
this.Menu = this.InputMenu;
this.Text = "PocketFSR" ;

}
#endregion

static void Main(){Applicat ion.Run(new Input());}
private void button1_Click(o bject sender, System.EventArg s e)
{
position = new fpositional(thi s);
}
private void button2_Click(o bject sender, System.EventArg s e)
{
position.clearA rrays();

}
}
}

*************fp ositional class********

using System;
using System.Drawing;
using System.Collecti ons;
using System.Windows. Forms;
using System.Data;

namespace PocketFSR
{
public class fpositional
{
ComboBoxArray cbArray; TextBoxArray tbArray;
public fpositional(Sys tem.Windows.For ms.Form f)
{

tbArray = new TextBoxArray(f) ;
cbArray = new ComboBoxArray(f );
for(int x = 0;x<5;x++)
{
cbArray.AddNewC omboBox();
tbArray.AddNewT extBox();
}
}

public void updateObjectsCo lors(int i)
{
Color klr, fklr;
switch (cbArray[i].SelectedItem.T oString())
{
case "Yes":
klr=Color.Light Green;
fklr= Color.Black;
break;
case "No":
klr=Color.Red;
fklr= Color.White;
break;
case "NA":
klr=Color.Black ;
fklr= Color.White;
break;
}

if (cbArray[i].SelectedItem != null && cbArray[i].SelectedItem.T oString()
!= "")
{
klr=Color.Red;
fklr= Color.White;
}
else
{
klr=Color.Light Green;
fklr= Color.Black;
}
tbArray[i].BackColor=klr;
tbArray[i].ForeColor=fklr ;
}
public void clearArrays()
{
cbArray.ClearAr ray();
tbArray.ClearAr ray();
}
}
}

*********TextBo xArray Class********** **

using System;

namespace PocketFSR
{
public class TextBoxArray : System.Collecti ons.CollectionB ase
{
private readonly System.Windows. Forms.Form HostForm;

public System.Windows. Forms.TextBox AddNewTextBox()
{
// Create a new instance of the TextBox class.
System.Windows. Forms.TextBox aTextBox = new
System.Windows. Forms.TextBox() ;
this.List.Add(a TextBox);
HostForm.Contro ls.Add(aTextBox );
// Set intial properties for the TextBox object.
aTextBox.Top = Count * 25;
aTextBox.Left = 0;
aTextBox.Multil ine=true;
aTextBox.Text = "TextBox " + this.Count.ToSt ring();
aTextBox.GotFoc us += new System.EventHan dler(GotFocusHa ndler);
aTextBox.LostFo cus += new System.EventHan dler(LostFocusH andler);
aTextBox.TextCh anged += new System.EventHan dler(TextChange dHandler);
return aTextBox;
}
public TextBoxArray(Sy stem.Windows.Fo rms.Form host) {HostForm = host;}
public System.Windows. Forms.TextBox this [int Index] {get{return
(System.Windows .Forms.TextBox) this.List[Index];}}
public void Remove(){if (this.Count >
0){HostForm.Con trols.Remove(th is[this.Count-1]); this.List.Remov eAt(this.Count -1);}}
public void ClearArray(){fo r (int i =
this.List.Count-1;i>-1;i--){HostForm.Cont rols.Remove(thi s[i]);this.List.Rem oveAt(i);}}
public void GotFocusHandler (Object sender, System.EventArg s e)
{
if (this[this.List.Index Of(sender)].Text != null &&
this[this.List.Index Of(sender)].Text != "")
{
this[this.List.Index Of(sender)].SelectionStart =
this[this.List.Index Of(sender)].Text.Length;
}
else
{
updateObjectsCo lors(this.List. IndexOf(sender) );
}
}
public void LostFocusHandle r(Object sender, System.EventArg s e)
{
updateObjectsCo lors(this.List. IndexOf(sender) );
}
public void TextChangedHand ler(Object sender, System.EventArg s e)
{
updateObjectsCo lors(this.List. IndexOf(sender) );
}
}
}

*********ComboB oxArray Class********** **

using System;

namespace PocketFSR
{
public class ComboBoxArray : System.Collecti ons.CollectionB ase
{
private readonly System.Windows. Forms.Form HostForm;
public System.Windows. Forms.ComboBox AddNewComboBox( )
{ // Create a new instance of the ComboBox class.
System.Windows. Forms.ComboBox aComboBox = new
System.Windows. Forms.ComboBox( );
this.List.Add(a ComboBox);
HostForm.Contro ls.Add(aComboBo x);
// Set intial properties for the ComboBox object.
//aComboBox.Size = System.Drawing. Size(46,20);
aComboBox.Top = Count * 25;
aComboBox.Left = 100;
aComboBox.Items .Add("NA");
aComboBox.Items .Add("Yes");
aComboBox.Items .Add("No");
aComboBox.Font= new
System.Drawing. Font("Tahoma",1 0,System.Drawin g.FontStyle.Bol d);
aComboBox.Selec tedIndexChanged += new
System.EventHan dler(SelectedIn dexChangedHandl er);
aComboBox.GotFo cus += new System.EventHan dler(GotFocusHa ndler);
return aComboBox;
}
public ComboBoxArray(S ystem.Windows.F orms.Form host){HostForm = host;}
public System.Windows. Forms.ComboBox this [int Index] { get {return
(System.Windows .Forms.ComboBox ) this.List[Index];}}
public void setPosition(){f or(int i =
0;i<this.List.C ount;i++){this[i].Top=0;}}
public void expand(int i){this[i].Top=0;this[i].BringToFront() ;}
public void Remove(){if (this.Count >
0){HostForm.Con trols.Remove(th is[this.Count-1]);this.List.Rem oveAt(this.Coun t
-1);}}
public void ClearArray(){fo r (int i =
this.List.Count-1;i>-1;i--){HostForm.Cont rols.Remove(thi s[i]);this.List.Rem oveAt(i);}}
public void GotFocusHandler (Object sender, System.EventArg s
e){this[this.List.Index Of(sender)].BackColor=Syst em.Drawing.Colo r.White;this[this.List.Index Of(sender)].ForeColor=Syst em.Drawing.Colo r.Black;}
public void SelectedIndexCh angedHandler(Ob ject sender, System.EventArg s e)
{ switch(this[this.List.Index Of(sender)].SelectedItem.T oString())
{
case "NA":
this[this.List.Index Of(sender)].BackColor=Syst em.Drawing.Colo r.Black;
this[this.List.Index Of(sender)].ForeColor=Syst em.Drawing.Colo r.White;
break;
case "No":
this[this.List.Index Of(sender)].BackColor=Syst em.Drawing.Colo r.Red;
this[this.List.Index Of(sender)].ForeColor=Syst em.Drawing.Colo r.White;
break;
case "Yes":
this[this.List.Index Of(sender)].BackColor=Syst em.Drawing.Colo r.LightGreen;
this[this.List.Index Of(sender)].ForeColor=Syst em.Drawing.Colo r.Black;
break;
}
updateObjectsCo lors(this.List. IndexOf(sender) );
}
}
}

Nov 16 '05 #1
3 3172
Hi Poewood,

Well, of course you get errors (I assume you mean compiler errors).
You call updateObjectsCo lors, but you don't say where the method is located, so the compiler will look inside the TextBoxArray/ComboBoxArray classes. And there are no updateObjectsCo lors method in either one.

You do, however, have the method in the fpositional class, but to use that one you will need to pass it as a reference when creating the arrays.

tbArray = new TextBoxArray(f, fp);

public TextBoxArray(Sy stem.Windows.Fo rms.Form host, fpositional fp)
{
HostForm = host;
parent_fpositio nal = fp;
}

....

parent_fpositio nal.updateObjec tsColors(...);

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
Poewood <Po*****@discus sions.microsoft .com> wrote:

<snip>
You will get errors with the updateObjectsCo lors() function in the Array
classes. It asks for an object reference but I can't seem to find the
reference.


What *exactly* does it do? Please post the *exact* error message.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Thanx Morten you were right on. I appreciate the time you took to help me.

Poe

"Morten Wennevik" wrote:
Hi Poewood,

Well, of course you get errors (I assume you mean compiler errors).
You call updateObjectsCo lors, but you don't say where the method is located, so the compiler will look inside the TextBoxArray/ComboBoxArray classes. And there are no updateObjectsCo lors method in either one.

You do, however, have the method in the fpositional class, but to use that one you will need to pass it as a reference when creating the arrays.

tbArray = new TextBoxArray(f, fp);

public TextBoxArray(Sy stem.Windows.Fo rms.Form host, fpositional fp)
{
HostForm = host;
parent_fpositio nal = fp;
}

....

parent_fpositio nal.updateObjec tsColors(...);

--
Happy coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2461
by: lawrence | last post by:
How dangerous or stupid is it for an object to have a reference to the object which contains it? If I have a class called $controllerForAll which has an arrray of all the objects that exist, what happens if one of those objects, when it is created, takes a reference to the object that contains it? Do bad things happen? class McShow {
2
13407
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class template and by setting output to a type library (DLL). All the object does is return a string value. At this point I have not checked the option to register for COM interop in Visual Studio So I go into Excel (where I want to use the object). Go to VB...
39
6543
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. When it completes, it can call a success, or a failure function. The names of these success, or failure functions will differ, and I'd like to know how I can pass the name of a function to my tool, and how my tool can call the function, using that...
3
3690
by: Alex Stevens | last post by:
Hi. I have a class and it exposes a property, which accepts a parameter collection object. I want the class to use the parameter object and update it. However I don't want to use a copy of the collection. So I innocently open up my class, and modify the Set sub to have BYRef instead of BYVal, and the IDE says 'Set' parameter cannot be declared as 'ByRef'. Why?
5
1653
by: Greg Vereschagin | last post by:
I'm trying to figure out a regular expression that will match the innermost tag and the contents in between. Specifically, the string that I am attempting to match looks as follows: ....<table>...<table>...>Final<...</table>...</table>... I want to match: <table>...>Final<...</table> from this example. The string could also, of course, look like the following:
14
2509
by: Robin Tucker | last post by:
Although I've been working on this project for 8 months now, I'm still not sure of the difference between ByVal and ByRef. As most objects in VB are reference types, passing ByVal I've discovered allows me to store a reference to the object I passed by val, to change that object and for the change to be reflected in the callers copy of the reference (confused?). Well, what is byref for in that case? I'm coming from a C++ background...
6
4889
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
9
3889
by: OuaisBla | last post by:
Although STL container can't support object by reference as a template argument. To make thing worse, allocator can't support stack based allocation. So: std::deque<std::string const &> is impossible to declare. But, it is also more than impossible to find a workaroung using a custom STL allocator because of the ugly and not object oriented design that was used. Thanks to many STL contributor for this, specially to PJ Plauger where...
11
2840
by: LayneMitch via WebmasterKB.com | last post by:
Hello. This is a reference file from a book I read in which the core subject is the use of 'event listeners'. I'm trying to load the file in Firefox and it's giving me an error message: Line: 5 Char: 1 Error: 'document' is undefined
0
8827
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8724
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9358
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9053
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6654
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4481
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3182
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2123
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.