Valid reasons for having Delphi AnsiString on Mobile platform…not only for Internet but for Shaders also. //…
Posted by jpluimers on 2017/12/27
It’s too bad that you need workarounds to get ByteStrings working on mobile devices as there are APIs there (like shaders) that work best with them.
There was a nice discussion on this last year at [WayBack] I miss AnsiString on Mobile…not only for Internet but for Shaders also.// FMX.Context.GLES.pasconstGLESHeaderHigh: array [0..24] of byte =(Byte(‘p), … – Paul TOTH – Google+ based in this code example in the FMX library undocumented unit FMX.Context.GLES:
// FMX.Context.GLES.pas const GLESHeaderHigh: array [0..24] of byte = (Byte('p'), Byte('r'), Byte('e'), Byte('c'), Byte('i'), Byte('s'), Byte('i'), Byte('o'), Byte('n'), Byte(' '), Byte('h'), Byte('i'), Byte('g'), Byte('h'), Byte('p'), Byte(' '), Byte(' '), Byte(' '), Byte('f'), Byte('l'), Byte('o'), Byte('a'), Byte('t'), Byte(';'), Byte(#13));
There are more than 500 places in the Delphi library sources that uses this construct and even more that do other fiddling (like [WayBack] TEncoding.GetBytes) to get from strings to bytes.
I wonder if by now we still need the workarounds that Andreas Hausladen provides:
- [Archive.is] Byte-Strings for Delphi 10 Seattle’s mobile compilers | Andy’s Blog and Tools
- [Archive.is] System.ByteStrings for 10.1 Berlin | Andy’s Blog and Tools
–jeroen
rvelthuis said
You do know, I hope, that the recent versions of Delphi do actually support
UTF8String
andRawByteString
on mobile platforms too? And even the older versions do accept 8-byte string constants, and allow you to use theMarshaledAString
type. So that FMX constant was simply made out of ignorance aboutcurrent Delphi. The programmer was not well known with Delphi yet, otherwise thiswould have been replaced by a simple
Move()
, etc.jpluimers said
Yet another reason to treat recent Embarcadero provided Delphi source code with care.
rvelthuis said
The code is fine, just overly complex.
Kazantsev Alexey said
We can use MarshaledAString:
// declaration
const
Signature = ‘magic signature’#13;
begin
// using. compiler’s magic does typecast without overhead
move(MarshaledAString(Signature)^, …someDestination… , Length(Signature));
jpluimers said
Now that is a cool idea. I didn’t know they had an alias for
PAnsiChar
that worked this way. Thanks!This was the documentation over time:
The fun thing: it was documented in XE2, but introduced in XE3!
rvelthuis said
The docs for XE2 show an empty page. That is not what I call “documented”. But it can be seen in the sources. Proper docs only appeared in XE4, as far as I can see. It makes sense: the low level C APIs on iOS use 8 bit strings, so there had to be a way to define and pass them, Only the higher level code uses 16 bit Unicode.