"
What I like about programming is, there is always more than 1 way to do the same thing."
I agree with you, Handoko. In programming there are many paths to the solution.
My game is an RTS and the main problem with it that I check the existence of gameunits not only in the main loop, but e.g. in FormPaint too, where I draw their picture. And in this case I get an error message and I don't know, why?
This is the code of checking everywhere in my program:
if numberofunits>0 then
begin
for i:=0 to numberofunits-1 do
begin
if not gameunits[i].exists then (...)
Maybe I'm organizing my program badly.
P.S: I just replaced this:
to this in my whole program:
and it seems the game works without errors. But I don't see why this is better? Just because I remove unnecessary instances this way:
freeandnil(gameunits[i]);
dec(numofunits,1);
setlength(gameunits,numofunits);
So after this remain some units? FreeAndNil doesn't remove immediately those instances?