2

Free Pascal docs state that RawByteString type is defined in Free Pascal but I cannot find where. One should expect that it is defined in System unit, like in Delphi, but when I compile (using FPC 2.6.2, {$mode delphi}) a function declaration

class function FromAnsi(const S: RawByteString): ByteArray; static;

I get the compiler error

Error: Identifier not found "RawByteString"

Guess I can declare the type myself:

type
  RawByteString = type AnsiString(CP_NONE);

but I would like to find the "native" FPC declaration.


Thanks for quick answers. Since I don't need to support FPC 1.x the workaround I need is:

{$IFDEF FPC}
{$IF FPC_VERSION = 2}
  {$IF FPC_RELEASE <= 6}
    type
      RawByteString = AnsiString;
  {$IFEND}
{$IFEND}
{$ENDIF}
kludg
  • 27,213
  • 5
  • 67
  • 118

2 Answers2

5

You need to use FPC 2.7.1.

The new string types do not exist in 2.6.x

BeniBela
  • 16,412
  • 4
  • 45
  • 52
  • 1
    I don't know about `RawByteString`, but `UnicodeString` has been available in FPC since at least 2.4.0, and FPC has `unicodestrings` and `delphiunicode` modes, and a `FPC_UNICODESTRINGS` define, to control/detect whether `string` maps to `AnsiString` or `UnicodeString`. – Remy Lebeau Sep 10 '14 at 16:36
  • @RemyLebeau: With "new string types" I refer to the strings with dynamical encoding, vs. `UnicodeString/WideString/AnsiString` with the statical encoding... (Although someone could already consider `AnsiString` a new string type, compared to `shortstring`) – BeniBela Sep 10 '14 at 19:27
2

From the documentation that you linked in the question:

Up to and including FPC 2.6.x, the RTL was based on the ones of Turbo Pascal and Delphi 7. This means it was primarily based around the shortstring, ansistring and pchar types. None of these types had any encoding information associated with them, but were implicitly assumed to be encoded in the "default system encoding" and were passed on to OS API calls without any conversion.

In Delphi 2009, Embarcadero switched the entire RTL over to the UnicodeString type, which represents strings using UTF-16. Additionally, they also made the AnsiString type "code page-aware". This means that AnsiStrings from then on contain the code page according to which their data should be interpreted.

FPC's language-level support for these string types is already available in current development versions of the compiler (FPC 2.7.1/trunk). The RTL level support is not yet complete. This page gives an overview of the code page-related behaviour of these string types, the current level of support in the RTL, and possible future ways of how this support may be improved.

In other words, you need at least 2.7 for the new D2009 alike string types.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490