I've tested your patch, it works for me (FPC 3.1.1 R32785, Lazarus R51073). In the bugtracker are four tickets about it as I wrote here: http://bugs.freepascal.org/view.php?id=29274