When adding to the array you have to set the new length and fill the record. It is not advisable to grow the array by one every time you need a new record - this is very slow and memory intensive. You should keep the number of enemies in a seperate variable and grow the array by a large chunk if it gets too small. If you cannot predict how many records you will need the most efficient solution (in terms of speed, not necessarily memory) is to double the size of the array every time it gets to small.
Another thing: a common naming convention in Delphi is to begin every type with a T. You should call your record TEnemy.
Adding a record to the array should look like this:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9:
| procedure AddEnemy(const AEnemy: TEnemy); begin if enemyCount >= Length(enemies) then begin SetLength(enemies, Length(enemies) * 2); end; enemies[enemyCount] := AEnemy; Inc(enemyCount); end; |
When searching the array you have to look at the used records only:
Delphi-Quelltext
1: 2: 3: 4:
| for i := 0 to enemyCount - 1 do begin ... end; |
Stefan
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.