Am 28.02.2012 08:22, schrieb Michael Schnell:
On 02/27/2012 09:51 PM, Martin Schreiber wrote:
A side mark: I don't think using the old ansistring as combined binary
and character buffer is such a bad thing.

+ 1/2


It would be better to have a type that 1:1 allows for all the well known
string operations, replacing "Character" by "Byte":

MyByte := MyByteString[n]

MyByteString := MyByteString + MyByte;

MyByteString2 := copy(MyByteString, 10, 100);

p:= pos(MyByteString2, MyByteString)

MyByteString := MyByteString + MyByteString2;

...


In my projects I usually do something like "Type ByteString =
AnsiString" for a future migration :) .

You know that this is already possible in FPC?

=== source begin ===

program bytearraytest;

{$mode objfpc}

type
  TByteArray = array of Byte;

operator + (aLeft, aRight: TByteArray): TByteArray;
begin
  SetLength(Result, Length(aLeft) + Length(aRight));
  if Length(aLeft) > 0 then
    Move(aLeft[0], Result[0], Length(aLeft) * SizeOf(Byte));
  if Length(aRight) > 0 then
    Move(aRight[0], Result[Length(aLeft)], Length(aRight) * SizeOf(Byte));
end;

var
  arr1, arr2, arr3: TByteArray;
  b: Byte;
  i: LongInt;
begin
  SetLength(arr1, 5);
  for i := 0 to 4 do
    arr1[i] := i + 1;
  SetLength(arr2, 5);
  for i := 0 to 4 do
    arr2[i] := i + 6;
  arr3 := arr1 + arr2;
  for b in arr3 do
    Write(b, ' ');
  Writeln;
  arr3 := Copy(arr2, 2, 2);
  for b in arr3 do
    Write(b, ' ');
  Writeln;
end.

=== source end ===

=== output begin ===
PS P:\tests\oneshots> .\bytearraytest.exe
1 2 3 4 5 6 7 8 9 10
8 9
=== output end ===

I only didn't implement Pos, but as this does not use any compiler magic you can do that yourself ;)

Regards,
Sven

--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to