Recent

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

CCRDude

  • Hero Member
  • *****
  • Posts: 596
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;
begin               
   StrToNSStr(AText, Result, kCFStringEncodingUTF8);
end;

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

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

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.

simonsayz

  • 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
 Simon,Choi

 

TinyPortal © 2005-2018