T
tcomer
Hello again, I've been struggling with this problem for two days now.
And either I'm getting a null object, or I'm overlooking something.
Basically what I have is this:
Form1 implements a class called ServerPropertyGrid object, which
implements a GameServer object. The GameServer object used a 'Player'
class which just holds player data. The 'GameServer' queries a game
server, and format the data for display/storage and also populates an
array of Player using the data, but keep in mind that is uses
asynchonous multithreading to handle the sockets.
What I'm trying to do is access the Player[] that is a part of the
GameServer object, from Form1
GameServer.cs
----------------------
GetServerData(); // gets/stores all returned info from the server
PopulatePlayerData(); // initializes and populates m_playerList with
Player data
public Player[] Players{ get { return m_playerList; }} /////// this
returns just fine
ServerPropertyGrid.cs
--------------------------------
ShowServerData(); // displays all server data in the grid
public Player[] Players{ get { return this.players; }} /////////
players[0].Name prints out what it's supposed to, so it's not null
here
private void GetPlayers(){ this.players = gameserver.Players; }
Form1.cs
--------------
serverGrid.GetResponse(ip, port);
this.playerList = serverGrid.Players; /// PROBLEM LINE
in Form1 the serverGrid.Players object is null, and the code I've
provided is the only places that the objects are modified. Using
this.ServerPropertyGrid.GameServer.Players to access the Player array
throws a NullReferenceException, which doesn't make sense, because
it's not null unless I try to access it from Form1. I've tried
this.ServerPropertyGrid.GameServer.Players, and I've also tried
Invoking a "GetPlayers" method using a delegate which gets the
Players[] and assigns it to a local object - neither solutions worked.
Any ideas?
I have no problem with sharing the actual project, if it would help
make my problem more clear. Thanks
And either I'm getting a null object, or I'm overlooking something.
Basically what I have is this:
Form1 implements a class called ServerPropertyGrid object, which
implements a GameServer object. The GameServer object used a 'Player'
class which just holds player data. The 'GameServer' queries a game
server, and format the data for display/storage and also populates an
array of Player using the data, but keep in mind that is uses
asynchonous multithreading to handle the sockets.
What I'm trying to do is access the Player[] that is a part of the
GameServer object, from Form1
GameServer.cs
----------------------
GetServerData(); // gets/stores all returned info from the server
PopulatePlayerData(); // initializes and populates m_playerList with
Player data
public Player[] Players{ get { return m_playerList; }} /////// this
returns just fine
ServerPropertyGrid.cs
--------------------------------
ShowServerData(); // displays all server data in the grid
public Player[] Players{ get { return this.players; }} /////////
players[0].Name prints out what it's supposed to, so it's not null
here
private void GetPlayers(){ this.players = gameserver.Players; }
Form1.cs
--------------
serverGrid.GetResponse(ip, port);
this.playerList = serverGrid.Players; /// PROBLEM LINE
in Form1 the serverGrid.Players object is null, and the code I've
provided is the only places that the objects are modified. Using
this.ServerPropertyGrid.GameServer.Players to access the Player array
throws a NullReferenceException, which doesn't make sense, because
it's not null unless I try to access it from Form1. I've tried
this.ServerPropertyGrid.GameServer.Players, and I've also tried
Invoking a "GetPlayers" method using a delegate which gets the
Players[] and assigns it to a local object - neither solutions worked.
Any ideas?
I have no problem with sharing the actual project, if it would help
make my problem more clear. Thanks