Author Topic: iOS_Controls by simonsayz - UTF-8 fix  (Read 3392 times)


  • Hero Member
  • *****
  • Posts: 502
iOS_Controls by simonsayz - UTF-8 fix
« on: November 25, 2014, 09:54:54 am »
I recently implemented my first iOS app using FreePascal and based it upon simonsayz' great demos. His iOS_Controls unit makes things really easy.

While working with that, I came across a bug - while FPC Unicode support refers to UTF-8 as the code charset, his units ignore the charset by using NSStr() from unit CoreFoundation.pas.

His iOS_Controls folder already contains unit NSHelpers.pas, which offers a better procedure (StrToNSStr). If we wrap this procedure into a function, NSStrUTF8 in the example, we can use hard-coded UTF-8 strings with only minor changes to his code.

Code: [Select]
function NSStrUTF8(AText: String): NSString;
   StrToNSStr(AText, Result, kCFStringEncodingUTF8);

Procedure TiOSTextView.Lines_Append( Str : String );
  FControl.setText( FControl.Text.stringByAppendingString
  //                     ( NSStr(PChar(Str))) );
                         ( NSStrUTF8(Str)) );

Procedure TiOSTextView.Lines_Add   ( Str : String );
  FControl.setText( FControl.Text.stringByAppendingString
  //                   ( NSStr(PChar(Char(13)+Str)) ) );
                       ( NSStrUTF8(Char(13)+Str) ) );

I did the same changes in a few other places with success (SetTabBar, various Captions and Prompts).

Haven't found a better place to report the bug yet, will email him as well, but in case anyone else is stumbling across this issue, here's the solution.


  • New Member
  • *
  • Posts: 27
Re: iOS_Controls by simonsayz - UTF-8 fix
« Reply #1 on: November 27, 2014, 01:06:03 pm »
 Thanks a lot.

 I will fix the code as you point.

 Best Regards


TinyPortal © 2005-2018