Your routine to reverse the string is a bit suboptimal.
FreePascal has a ReverseString function in strutils unit.
If you cannot (or do not want to) include that unit, simply copy the code from there.
Alternatively (see also
my website, which has some other "suboptimal" ones as well, but this one is OK):
function ReverseString(const S: String): String;
var i,j: LongInt;
begin
j := Length(S);
Setlength(Result,j);
i := 1;
while i <= j do //Actually this is faster than a for loop
begin
result[i] := S[j-i+1];
inc(i);
end;
end;
Why can't or won't you sue the Str() function?
Bart