Recent

Author Topic: New FPC3 AnsiString - WideString conversion problem  (Read 3563 times)

agorka

  • New Member
  • *
  • Posts: 25
New FPC3 AnsiString - WideString conversion problem
« on: May 19, 2016, 04:15:53 pm »
Hello everyone.

I faced strange problem. I have a project I'm working on for a couple of years, and I use Lazarus to port it to Mac / OSX / Darwin.
After upgrading to Lazarus 1.6 I've a got a huge number of problems with international symbols in strings.

I made a new test project, containing:
procedure TForm1.FormCreate(Sender: TObject);
var S : String;
    W : WideString;
begin
  S:='Привет';
  ShowMessage(S);
  W:=S;
  ShowMessage(W);
  S:=W;
  ShowMessage(S);
end;

It works perfectly.
When I add the same code to my existing project, I get only first message displayed correctly, 2nd and 3rd message contain only '??????'.
What should I change in my existing project so String<->Widestring conversion would work correctly?

Please help! Thanks in advance.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: New FPC3 AnsiString - WideString conversion problem
« Reply #1 on: May 19, 2016, 04:20:20 pm »
are your existing project source files using cp1251 encoding?
(right click in the source editor File Settings -> Encoding)

agorka

  • New Member
  • *
  • Posts: 25
Re: New FPC3 AnsiString - WideString conversion problem
« Reply #2 on: May 19, 2016, 04:31:29 pm »
No, it is set to UTF8, so I had to replace 'Привет' to
  S:=#$D0#$9F#$D1#$80#$D0#$B8#$D0#$B2;
It shows 'Прив' on first ShowMessage and ???????? on second and 3rd.
With the new test project it shows 'Прив' 3 times.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: New FPC3 AnsiString - WideString conversion problem
« Reply #3 on: May 19, 2016, 04:39:30 pm »
Odd.
What happens if you add the explicit codepage utf8 setting to the file?
Code: Pascal  [Select][+][-]
  1. unit ..
  2. {$codepage utf8}
  3. ...
  4. interface
  5.  

agorka

  • New Member
  • *
  • Posts: 25
Re: New FPC3 AnsiString - WideString conversion problem
« Reply #4 on: May 19, 2016, 04:47:26 pm »
I added this both to lpr and pas file and nothing changed.
It's not the source encoding problem, cause in my project I get strings from .mo files with gnugettext, and I see that they are loaded correctly, but upon any Wide<>Ansi conversion strings get corrupt. I put lots of LazUTF8.UTF16toUTF8 and vise versa calls to fix everything in gnugettext unit, but now I have problems with FileExists function and it have inside conversions I can't fix.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: New FPC3 AnsiString - WideString conversion problem
« Reply #5 on: May 19, 2016, 04:56:14 pm »
and what's the difference between the "new" and "existing" project configurations?

agorka

  • New Member
  • *
  • Posts: 25
Re: New FPC3 AnsiString - WideString conversion problem
« Reply #6 on: May 19, 2016, 05:44:51 pm »
I think I found the problem.
In my test project, when I list uses in this order:

uses
{$IFDEF DARWIN}
  CThreads,
{$ENDIF}
  Interfaces,
  Forms,

it works well.
When I swap interfaces and forms:
uses
{$IFDEF DARWIN}
  CThreads,
{$ENDIF}
  Forms,
  Interfaces,

 I get this conversion problem.

After swapping those units in my old project, I got it running without any problems and was able to load the file with international filename!
So, the problem is solved.
Still, I spent a week fighting with this problem, and a warning or hint or error message would really help.

Thaddy

  • Hero Member
  • *****
  • Posts: 17099
  • Ceterum censeo Trump esse delendam
Re: New FPC3 AnsiString - WideString conversion problem
« Reply #7 on: May 19, 2016, 05:58:49 pm »
Now, glad you have solved this but plz note:
Code: Pascal  [Select][+][-]
  1. uses
  2. {.$IFDEF DARWIN}  // don't
  3. {$IFDEF UNIX}  //do
  4.   CThreads,
  5. {$ENDIF}
  6.   Interfaces,
  7.   Forms,
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

 

TinyPortal © 2005-2018