Premier2k
August 8th, 2009, 02:53 PM
I've just been musing over a problem I had and the solution and I thought of another problem that I would encounter, so I checked it and it is a problem....
After setting territories and continents, the user enters a borders screen.
When the form loads it populates a drop down box with the territory names that it gets from collection and a listbox (called lbUnassigned) with the same information. The user selects a territory from the drop down box and then proceeds to add territories from the listbox to another list box (lbBorder). When the user presses SAVE then the territory is removed from the dropdown and the two list boxes are reset, i.e lbBorders is empty and lbUnassigned is cleared and repopulated with the list of territories.
Except that when the user presses SAVE, the territory disappears from the dropdown (correct) and the same territory is added AGAIN to the lbUnassigned box (wrong) I think what's happening is another example of incorrect usage of overloaded constructors.
This is my class that holds the collection:
class Territories
{
string tname;
int sx, sy, lx, ly, neutVal;
bool cbS, cbK, cbN, cbB;
public ArrayList aBorder, aBombard;
public enum ArrayListType { border = 1, bombard = 2 }
public string Tname
{
get { return this.tname; }
set { this.tname = value; }
}
public int Sx
{
get { return this.sx; }
set { this.sx = value; }
}
public int Sy
{
get { return this.sy; }
set { this.sy = value; }
}
public int Lx
{
get { return this.lx; }
set { this.lx = value; }
}
public int Ly
{
get { return this.ly; }
set { this.ly = value; }
}
public int NeutVal
{
get { return this.neutVal; }
set { this.neutVal = value; }
}
public bool CbS
{
get { return this.cbS; }
set { this.cbS = value; }
}
public bool CbK
{
get { return this.cbK; }
set { this.cbK = value; }
}
public bool CbN
{
get { return this.cbN; }
set { this.cbN = value; }
}
public bool CbB
{
get { return this.cbB; }
set { this.cbB = value; }
}
public Territories(string tname, int sx, int sy, int lx, int ly, bool cbS, bool cbK, bool cbN, bool cbB)
{
this.Tname = tname;
this.Sx = sx;
this.Sy = sy;
this.Lx = lx;
this.Ly = ly;
this.CbS = cbS;
this.CbK = cbK;
this.CbN = cbN;
this.CbB = cbB;
}
public Territories(string tname, int sx, int sy, int lx, int ly, bool cbS, bool cbK, bool cbN, bool cbB, int neutVal)
{
this.Tname = tname;
this.Sx = sx;
this.Sy = sy;
this.Lx = lx;
this.Ly = ly;
this.CbS = cbS;
this.CbK = cbK;
this.CbN = cbN;
this.CbB = cbB;
this.NeutVal = neutVal;
}
public Territories(string tname, ArrayList list, ArrayListType type)
{
this.Tname = tname;
if (type == ArrayListType.border)
{
this.aBorder = list;
}
else if (type == ArrayListType.bombard)
{
this.aBombard = list;
}
}
}
static class gbl_lisjt
{
static gbl_lisjt()
{
Debug.WriteLine("** creating application scope instance **");
lijst = new List<Territories> ();
}
static public List<Territories> lijst;
}
So, as you can see I am again using tname when assigning the borders and bombards:
public Territories(string tname, ArrayList list, ArrayListType type)
{
this.Tname = tname;
if (type == ArrayListType.border)
{
this.aBorder = list;
}
else if (type == ArrayListType.bombard)
{
this.aBombard = list;
}
}
Now later on, I need to be able to loop through my collection and look at tname and then find out what borders it has, but as far as I'm aware, the collection doesn't know any relationship between them. So removing the string tname from the method would just give me a list of borders in an array wouldn't it? How do I know which borders were allocated to which territory?
Premier2k
After setting territories and continents, the user enters a borders screen.
When the form loads it populates a drop down box with the territory names that it gets from collection and a listbox (called lbUnassigned) with the same information. The user selects a territory from the drop down box and then proceeds to add territories from the listbox to another list box (lbBorder). When the user presses SAVE then the territory is removed from the dropdown and the two list boxes are reset, i.e lbBorders is empty and lbUnassigned is cleared and repopulated with the list of territories.
Except that when the user presses SAVE, the territory disappears from the dropdown (correct) and the same territory is added AGAIN to the lbUnassigned box (wrong) I think what's happening is another example of incorrect usage of overloaded constructors.
This is my class that holds the collection:
class Territories
{
string tname;
int sx, sy, lx, ly, neutVal;
bool cbS, cbK, cbN, cbB;
public ArrayList aBorder, aBombard;
public enum ArrayListType { border = 1, bombard = 2 }
public string Tname
{
get { return this.tname; }
set { this.tname = value; }
}
public int Sx
{
get { return this.sx; }
set { this.sx = value; }
}
public int Sy
{
get { return this.sy; }
set { this.sy = value; }
}
public int Lx
{
get { return this.lx; }
set { this.lx = value; }
}
public int Ly
{
get { return this.ly; }
set { this.ly = value; }
}
public int NeutVal
{
get { return this.neutVal; }
set { this.neutVal = value; }
}
public bool CbS
{
get { return this.cbS; }
set { this.cbS = value; }
}
public bool CbK
{
get { return this.cbK; }
set { this.cbK = value; }
}
public bool CbN
{
get { return this.cbN; }
set { this.cbN = value; }
}
public bool CbB
{
get { return this.cbB; }
set { this.cbB = value; }
}
public Territories(string tname, int sx, int sy, int lx, int ly, bool cbS, bool cbK, bool cbN, bool cbB)
{
this.Tname = tname;
this.Sx = sx;
this.Sy = sy;
this.Lx = lx;
this.Ly = ly;
this.CbS = cbS;
this.CbK = cbK;
this.CbN = cbN;
this.CbB = cbB;
}
public Territories(string tname, int sx, int sy, int lx, int ly, bool cbS, bool cbK, bool cbN, bool cbB, int neutVal)
{
this.Tname = tname;
this.Sx = sx;
this.Sy = sy;
this.Lx = lx;
this.Ly = ly;
this.CbS = cbS;
this.CbK = cbK;
this.CbN = cbN;
this.CbB = cbB;
this.NeutVal = neutVal;
}
public Territories(string tname, ArrayList list, ArrayListType type)
{
this.Tname = tname;
if (type == ArrayListType.border)
{
this.aBorder = list;
}
else if (type == ArrayListType.bombard)
{
this.aBombard = list;
}
}
}
static class gbl_lisjt
{
static gbl_lisjt()
{
Debug.WriteLine("** creating application scope instance **");
lijst = new List<Territories> ();
}
static public List<Territories> lijst;
}
So, as you can see I am again using tname when assigning the borders and bombards:
public Territories(string tname, ArrayList list, ArrayListType type)
{
this.Tname = tname;
if (type == ArrayListType.border)
{
this.aBorder = list;
}
else if (type == ArrayListType.bombard)
{
this.aBombard = list;
}
}
Now later on, I need to be able to loop through my collection and look at tname and then find out what borders it has, but as far as I'm aware, the collection doesn't know any relationship between them. So removing the string tname from the method would just give me a list of borders in an array wouldn't it? How do I know which borders were allocated to which territory?
Premier2k