SOLVED
The problem was the different definition of the method in the implementation section.
The code was ported from Delphi and at the method's definition a variable was declared as Char but in the implementation section was declared as ANSIchar (as it was in Delphi). I can't recall if I was me who changed the declarations or the code transporter.
Anyway thanks for your help