Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-02

Problem with StrMove() in a unit compilable in FPC and Delphi

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hello,

I want to use the StrMove() function in a unit compilable in Delphi (XE) and FPC, but I don't know why it doesn't work on FPC.

Consider the following code:

{$IFDEF FPC}
{$codepage utf8} // I need to keep my unit in UTF-8
{$ENDIF}
var
  a: AnsiString;
  la: Integer;
  pa: PAnsiChar;
  b: Byte;
  bs: TBytes;
begin
  a := 'aã';
  pa := @a[1];
  la := strlen(pa);
  WriteLn('L: ', la);
  SetLength(bs, la);
  StrMove(@bs[0], pa, la);
  for b in bs do
    WriteLn(b);
end;

On Delphi, I get:

*L: 2*
97
227

Perfect, checking it via a character map, the 227 is the keystroke Alt+0227 that is the "ã" character, however, when I try this code in FPC (from trunk), I get:

*L: 3*
97
195
163

And finally a get a wrong content in my final buffer.

So, is the FPC StrMove() function compatible with the Delphi one?

Thank you!

Silvio Clécio
Jonas Maebe
to silvioprog

On 25/02/16 19:31, silvioprog wrote:

So, is the FPC StrMove() function compatible with the Delphi one?

This has nothing to do with StrMove, since clearly the original string is already different. If you compile your source code in Delphi with --codepage=65001, it should give the same result as with FPC and {$codepage utf8}.

Jonas

silvioprog
to Jonas Maebe
Jonas Maebe wrote 8 lines
On 25/02/16 19:31, silvioprog wrote: So, is the FPC StrMove() function compatible with the Delphi one? This has nothing to do with StrMove, since clearly the original string is already different. If you compile your source code in Delphi with --codepage=65001, it should give the same result as with FPC and {$codepage utf8}.

Indeed. But, what I need to do? Because this code below still returning "L: 3 - 97 195 163":

program Project1;
{$mode objfpc}{$H+}
{$codepage cp1252} // I don't know where I found all list of supported
codepages here ...
uses
  sysutils;
var
  a: AnsiString;
  la: Integer;
  pa: PAnsiChar;
  b: Byte;
  bs: TBytes;
begin
  a := 'aã';
  pa := @a[1];
  la := strlen(pa);
  Write('L: ', la, ' - ');
  SetLength(bs, la);
  StrMove(@bs[0], pa, la);
  for b in bs do
    Write(b, ' ');
  ReadLn;
end.
Silvio Clécio
silvioprog
to silvioprog
silvioprog wrote 16 lines
On Thu, Feb 25, 2016 at 3:47 PM, Jonas Maebe wrote: > On 25/02/16 19:31, silvioprog wrote: > > So, is the FPC StrMove() function compatible with the Delphi one? > > This has nothing to do with StrMove, since clearly the original string is > already different. If you compile your source code in Delphi with > --codepage=65001, it should give the same result as with FPC and {$codepage > utf8}. Indeed. But, what I need to do? Because this code below still returning "L: 3 - 97 195 163":

Oh, just changed the source encoding and now it works fine. ^^'

Silvio Clécio
silvioprog
to silvioprog

Well, the problem persists, and I can't understand why this attached project works only if compiled with Delphi. The results:

Delphi:

Length: 3
aañ

FPC:

Length: 5
aA£A±

Lazarus 1.6 r51630 FPC 3.0.0 i386-win32-win32/win64

Silvio Clécio
silvioprog
to silvioprog
silvioprog wrote 15 lines
Well, the problem persists, and I can't understand why this attached project works only if compiled with Delphi. The results: Delphi: Length: 3 aañ FPC: Length: 5 aA£A± Lazarus 1.6 r51630 FPC 3.0.0 i386-win32-win32/win64

Just sharing my whole problem, I'm trying to use a ANSI C library with FPC on Windows, but I don't know why it doesn't work. The small demo showing the problem can be found here (both Pascal and C sources):

https://www.dropbox.com/s/ilpti4arhylly24/ansi_test_c_lib.zip?dl=1

(I use a third party library, the "ansi_test.c" is just to reproduce the problem)

It just concat the 'â' and 'é' characters, but it works only on Delphi, that prints "2 \n âé" in the console. With FPC it prints "4 \n A¢Ac". :-/

Silvio Clécio