Hello,
I am working on a small game and have run into the following problem. Sometimes when I call .free on a certain derived class, I get an AV. Other times I do not. Here's the details.
I have the following classes:
TAI from (TPersistent)
TPlayer from (TAI)
TMonster from (TAI)
TMaze from (TPersistent) that holds the maze, an array of 6 TPlayers, and the TMonster.
I do all manipulation on the classes from public methods. I also have a GUI (holding a TMaze called GameMaze) that displays a grid of the TPlayer stats and a grid of the TMonster stats.
I have two procedures in the form that update the grids by calling public methods in GameMaze: UpdatePlayerGrid and UpdateMonsterGrid. The first time the program calls the updaters (after NewGame1Click) everything is fine. But when it calls the Monster updater after the first move, things go bonkers.
The UpdatePlayerGrid has very similar code, but it appears to work fine. The main difference is that the player proc uses an instance of TPlayer instead of TMonster and has a loop to process all 6 players, but the TPlayer.free at the end works just fine. Does anyone have any ideas?
Thank you
I am working on a small game and have run into the following problem. Sometimes when I call .free on a certain derived class, I get an AV. Other times I do not. Here's the details.
I have the following classes:
TAI from (TPersistent)
TPlayer from (TAI)
TMonster from (TAI)
TMaze from (TPersistent) that holds the maze, an array of 6 TPlayers, and the TMonster.
I do all manipulation on the classes from public methods. I also have a GUI (holding a TMaze called GameMaze) that displays a grid of the TPlayer stats and a grid of the TMonster stats.
I have two procedures in the form that update the grids by calling public methods in GameMaze: UpdatePlayerGrid and UpdateMonsterGrid. The first time the program calls the updaters (after NewGame1Click) everything is fine. But when it calls the Monster updater after the first move, things go bonkers.
Code:
procedure TMainForm.UpdateMonsterGrid;
var
Monster: TMonster;
begin
Monster:= TMonster.Create(0);
try
Monster:= GameMaze.GetMonsterInfo;
with sgMonster do begin
//fill the grid with the information.
end; {with}
finally
Monster.free; //this line bombs the second time through
end; {try/finally}
end;
The UpdatePlayerGrid has very similar code, but it appears to work fine. The main difference is that the player proc uses an instance of TPlayer instead of TMonster and has a loop to process all 6 players, but the TPlayer.free at the end works just fine. Does anyone have any ideas?
Thank you