Weird problem using standard Trim function using unicode

Delphi XE4
In our scripts we are using the Trim function, but it does something weird with Unicode strings

A short explanation about the scripts
Success signals if the outcome is correct (we can set this to false if a check fails)
knownas, surname, fullname are registerd variables of type btUnicodeString
SetNotNull is a procedure that we use to signal if a registerd variable has changed.

Input values:
knownas : 'Мы предлагаем’
surname : 'Вам предлагаем’
expected out value for displayname and fullname : 'Мы предлагаем Вам предлагаем’
wrong out put value : ‘?? ??? Вам предлагаем’

In both scripts the trim function is called twice:
1- Stack.SetUnicodeString(-1, SysUtils.Trim(Stack.GetUnicodestring(-2)))
2- Stack.SetWideString(-1, SysUtils.Trim(Stack.GetWideString(-2)))

Which I find a bit weird, why is the second time always the GetWideString variant called and not the GetUnicodestring??

Original script that produces wrong output

begin
fullname := Trim(Trim(knownas) + ’ ’ + surname);
SetNotNull(‘fullname’);

displayname := fullname;
SetNotNull(‘displayname’);

Success := True;
end.

Modified script that produces right ouput

var
tmpKnownAs : string;
tmpFullName : string;
begin
tmpKnownAs := Trim(knownas);
tmpFullName := Trim(tmpKnownAs + ’ ’ + surname);
fullname := tmpFullName;
SetNotNull(‘fullname’);

displayname := fullname;
SetNotNull(‘displayname’);

Success := True;
end.

regards
Paul

One more addition:
Just changed the script to use our own function:

function TdmHDSPascalScript.HDSUnicodeTrim(const Value: string): string;
begin
Result := Trim(Value);
end;

And this works as expected…

Script now looks like:

begin
fullname := HDSUnicodeTrim(HDSUnicodeTrim(knownas) + ’ ’ + surname);
SetNotNull(‘fullname’);

displayname := fullname;
SetNotNull(‘displayname’);

Success := True;
end.

regards
Paul

Hello,
Thanks, the issue was logged as #51
As a workaround you can change uPSCompiler.pas file:

AddFunction(‘Function Trim(s : WideString) : WideString;’); //instead of AnyString