1. Make Lazarus-compatible (CodeTyphon 3.10)
2. Sync with some fixes from Avemey