Code Snippets Database
Control Box
Requested snippets
This page displays 6 requested snippets.
You can choose a category, perform a search or generate a Pascal unit containing the snippets by using the Control Box.
- AppendByteArray
-
Appends array of bytes B2 to the end of byte array B1.
procedure AppendByteArray(var B1: TBytes; const B2: array of Byte); var OldB1Len: Integer; begin if Length(B2) = 0 then Exit; OldB1Len := Length(B1); SetLength(B1, OldB1Len + Length(B2)); Move(B2[0], B1[OldB1Len], Length(B2)); end;Kind of Snippet: RoutineRequired units: None.Required snippets: TBytes.See also: ConcatByteArrays.Supported Compilers:D2 D3 D4 D5 D6 D7 D2005 D2006 D2007 D2009 D2010 DXE DXE2 Free
Pascal












This snippet cannot be included in generated units. - ByteArraysEqual
-
Checks if two byte arrays are equal. The arrays are equal if they have the same number of elements and elements at the same position in the array are equal.
function ByteArraysEqual(const B1, B2: array of Byte): Boolean; var I: Integer; begin Result := Length(B1) = Length(B2); if Result then begin for I := 0 to High(B1) do begin if B1[I] <> B2[I] then begin Result := False; Exit; end; end; end; end;Kind of Snippet: RoutineRequired units: None.Required snippets: None.See also: None.Supported Compilers:D2 D3 D4 D5 D6 D7 D2005 D2006 D2007 D2009 D2010 DXE DXE2 Free
Pascal













- ChopByteArray
-
Deletes a sequence of bytes from byte array B starting at index Start with length Len. If either Start or Len are less than 0 they are taken as zero. If Start is beyond the end of the array or if Len is 0 the whole array is returned unchanged. If the sequence of bytes to be chopped extends beyond the end of the array it is truncated from Start.
function ChopByteArray(const B: array of Byte; Start, Len: Integer): TBytes; var First, Last: TBytes; begin if Start < 0 then Start := 0; if Len < 0 then Len := 0 else if Start >= Length(B) then Len := 0 else if Start + Len > Length(B) then Len := Length(B) - Start; First := SliceByteArray(B, 0, Start); Last := SliceByteArray(B, Start + Len, Length(B)); Result := ConcatByteArrays(First, Last); end;Kind of Snippet: RoutineRequired units: None.See also: SliceByteArray.Supported Compilers:D2 D3 D4 D5 D6 D7 D2005 D2006 D2007 D2009 D2010 DXE DXE2 Free
Pascal












This snippet cannot be included in generated units. - CloneByteArray
-
Makes a copy of an array of bytes.
function CloneByteArray(const B: array of Byte): TBytes; begin SetLength(Result, Length(B)); if Length(B) > 0 then Move(B[0], Result[0], Length(B)); end;Kind of Snippet: RoutineRequired units: None.Required snippets: TBytes.See also: AppendByteArray.Supported Compilers:D2 D3 D4 D5 D6 D7 D2005 D2006 D2007 D2009 D2010 DXE DXE2 Free
Pascal












This snippet cannot be included in generated units. - ConcatByteArrays
-
Concatenates two byte arrays B1 and B2 and returns the resulting array. The result is the contents of B1 followed by the contents of B2.
function ConcatByteArrays(const B1, B2: array of Byte): TBytes; begin Result := CloneByteArray(B1); AppendByteArray(Result, B2); end;
Kind of Snippet: RoutineRequired units: None.See also: AppendByteArray.Supported Compilers:D2 D3 D4 D5 D6 D7 D2005 D2006 D2007 D2009 D2010 DXE DXE2 Free
Pascal












This snippet cannot be included in generated units. - SliceByteArray
-
Slices a range of bytes starting at index Start with length Len from byte array B and returns thr result. If either Start or Len are less than 0, they are taken as 0. If Start is beyond the end of the array or if Len is 0 an empty array is returned. If the sequence of bytes to be sliced extends beyond the end of the array it is truncated from Start.
function SliceByteArray(const B: array of Byte; Start, Len: Integer): TBytes; begin if Start < 0 then Start := 0; if Len < 0 then Len := 0 else if Start >= Length(B) then Len := 0 else if Start + Len > Length(B) then Len := Length(B) - Start; SetLength(Result, Len); if Len > 0 then Move(B[Start], Result[0], Len); end;Kind of Snippet: RoutineRequired units: None.Required snippets: TBytes.See also: ChopByteArray.Supported Compilers:D2 D3 D4 D5 D6 D7 D2005 D2006 D2007 D2009 D2010 DXE DXE2 Free
Pascal












This snippet cannot be included in generated units.
