Pressing 0 creates a range error in FormKeyUp because hands is defined as array [kcomp..khuman, kclubs..kspades, 1..13] of boolean.
Anyway, there are some issues with the code, imo:
- Game logic is intertwined with presentation. Consider creating a "Game : TGame" record or class that contains only the game-related things. It should be possible to use it without changes in a console program or in a GUI.
- Consider skipping the Randomize call for debugging. This allows hunting for reproducible bugs.
- Instead of using several structures (card_num, deck, etc.), consider creating the cards as their own objects, with attributes like suit and value. Then create decks, hands and books as containers that can hold any amount of cards.
I've attached a partially rewritten version.
(EDIT: books don't even have to be created as containers, they can be checked dynamically.)