---
product: Chilkat
product_version: 11.7.0
language: delphidll
language_label: Delphi DLL
class: CkByteData
license: free
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/dd_CkByteDataRef.html
---
# Chilkat CkByteData — Delphi DLL — v11.7.0

> Chilkat 11.7.0 · language=delphidll · class=CkByteData
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/CkByteData.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/delphidll/guide.md`.

## Purpose

Represents a chunk of byte data and provides methods for accessing it, adding to it, or saving and loading from files.

## Object creation, unlocking and error handling

**Create/Dispose**

```pascal
var
myObject: HCkByteData;

begin
myObject := CkByteData_Create();

// ...

CkByteData_Dispose(myObject);
end;
```

`function CkByteData_Create: HCkByteData; stdcall;`

Creates an instance of the HCkByteData object and returns a handle (i.e. a Pointer). The handle is passed in the 1st argument for the functions listed on this page.

`procedure CkByteData_Dispose(handle: HCkByteData); stdcall;`

Objects created by calling CkByteData_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function.

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in Delphi DLL.

## Member index

| Member | Kind | Signature |
|---|---|---|
| `SecureClear` | property, read/write | `function CkByteData_getSecureClear(objHandle: HCkByteData): wordbool; stdcall; procedure CkByteData_putSecureClear(objHandle: HCkByteData; newPropVal: wordbool); stdcall;` |
| `appendChar` | method | `procedure CkByteData_appendChar(objHandle: HCkByteData;     ch: Char) stdcall;` |
| `appendCharN` | method | `procedure CkByteData_appendCharN(objHandle: HCkByteData;     ch: Char;     numTimes: Integer) stdcall;` |
| `appendEncoded` | method | `procedure CkByteData_appendEncoded(objHandle: HCkByteData;     str: pbyte;     encoding: pbyte) stdcall;` |
| `appendEncodedW` | method | `procedure CkByteData_appendEncodedW(objHandle: HCkByteData;     str: PWideChar;     encoding: PWideChar) stdcall;` |
| `appendFile` | method | `function CkByteData_appendFile(objHandle: HCkByteData;     path: pbyte): wordbool; stdcall;` |
| `appendFileW` | method | `function CkByteData_appendFileW(objHandle: HCkByteData;     path: PWideChar): wordbool; stdcall;` |
| `appendInt` | method | `procedure CkByteData_appendInt(objHandle: HCkByteData;     intValue: Integer;     littleEndian: wordbool) stdcall;` |
| `appendRandom` | method | `procedure CkByteData_appendRandom(objHandle: HCkByteData;     numBytes: Integer) stdcall;` |
| `appendShort` | method | `procedure CkByteData_appendShort(objHandle: HCkByteData;     shortValue: SmallInt;     littleEndian: wordbool) stdcall;` |
| `appendStr` | method | `procedure CkByteData_appendStr(objHandle: HCkByteData;     str: pbyte) stdcall;` |
| `appendStrW` | method | `procedure CkByteData_appendStrW(objHandle: HCkByteData;     str: PWideChar;     charset: PWideChar) stdcall;` |
| `byteSwap4321` | method | `procedure CkByteData_byteSwap4321(objHandle: HCkByteData) stdcall;` |
| `clear` | method | `procedure CkByteData_clear(objHandle: HCkByteData) stdcall;` |
| `dropData` | method | `procedure CkByteData_dropData(objHandle: HCkByteData) stdcall;` |
| `encode` | method | `procedure CkByteData_encode(objHandle: HCkByteData;     encoding: pbyte;     str: HCkString) stdcall;` |
| `encodeW` | method | `procedure CkByteData_encodeW(objHandle: HCkByteData;     encoding: PWideChar;     str: HCkString) stdcall;` |
| `ensureBuffer` | method | `function CkByteData_ensureBuffer(objHandle: HCkByteData;     expectedNumBytes: LongWord): wordbool; stdcall;` |
| `getByte` | method | `function CkByteData_getByte(objHandle: HCkByteData;     byteIndex: LongWord): Byte; stdcall;` |
| `getChar` | method | `function CkByteData_getChar(objHandle: HCkByteData;     byteIndex: LongWord): Char; stdcall;` |
| `getData` | method | `function CkByteData_getData(objHandle: HCkByteData): pbyte; stdcall;` |
| `getDataAt` | method | `function CkByteData_getDataAt(objHandle: HCkByteData;     byteIndex: LongWord): pbyte; stdcall;` |
| `getEncoded` | method | `function CkByteData_getEncoded(objHandle: HCkByteData;     encoding: pbyte): pbyte; stdcall;` |
| `getEncodedW` | method | `function CkByteData_getEncodedW(objHandle: HCkByteData;     encoding: PWideChar): PWideChar; stdcall;` |
| `getInt` | method | `function CkByteData_getInt(objHandle: HCkByteData;     byteIndex: LongWord): Integer; stdcall;` |
| `getRange` | method | `function CkByteData_getRange(objHandle: HCkByteData;     byteIndex: LongWord;     numBytes: LongWord): pbyte; stdcall;` |
| `getSize` | method | `function CkByteData_getSize(objHandle: HCkByteData): LongWord; stdcall;` |
| `getUInt` | method | `function CkByteData_getUInt(objHandle: HCkByteData;     byteIndex: LongWord): LongWord; stdcall;` |
| `is7bit` | method | `function CkByteData_is7bit(objHandle: HCkByteData): wordbool; stdcall;` |
| `loadFile` | method | `function CkByteData_loadFile(objHandle: HCkByteData;     path: pbyte): wordbool; stdcall;` |
| `loadFileW` | method | `function CkByteData_loadFileW(objHandle: HCkByteData;     path: PWideChar): wordbool; stdcall;` |
| `pad` | method | `procedure CkByteData_pad(objHandle: HCkByteData;     blockSize: Integer;     paddingScheme: Integer) stdcall;` |
| `removeChunk` | method | `procedure CkByteData_removeChunk(objHandle: HCkByteData;     startIndex: LongWord;     numBytes: LongWord) stdcall;` |
| `removeData` | method | `function CkByteData_removeData(objHandle: HCkByteData): pbyte; stdcall;` |
| `replaceChar` | method | `procedure CkByteData_replaceChar(objHandle: HCkByteData;     existingByteValue: Byte;     replacementByteValue: Byte) stdcall;` |
| `saveFile` | method | `function CkByteData_saveFile(objHandle: HCkByteData;     path: pbyte): wordbool; stdcall;` |
| `saveFileW` | method | `function CkByteData_saveFileW(objHandle: HCkByteData;     path: PWideChar): wordbool; stdcall;` |
| `shorten` | method | `procedure CkByteData_shorten(objHandle: HCkByteData;     numBytes: LongWord) stdcall;` |
| `to_ws` | method | `function CkByteData_to_ws(objHandle: HCkByteData;     charset: pbyte): PWideChar; stdcall;` |
| `unpad` | method | `procedure CkByteData_unpad(objHandle: HCkByteData;     blockSize: Integer;     paddingScheme: Integer) stdcall;` |

Deprecated members are listed at the end of this file with their replacements; do not use them in new code.

## Properties

### CkByteData.SecureClear

`Chilkat 11.7.0 · delphidll · CkByteData · SecureClear · property · read/write · since 9.5.0.73`

```pascal
function CkByteData_getSecureClear(objHandle: HCkByteData): wordbool; stdcall;
procedure CkByteData_putSecureClear(objHandle: HCkByteData; newPropVal: wordbool); stdcall;
```

If set to `True`, then memory is always first overwritten with zero bytes prior to deallocation. The default value of this property is `False`.

## Methods

### CkByteData.appendChar

`Chilkat 11.7.0 · delphidll · CkByteData · appendChar · method`

```pascal
procedure CkByteData_appendChar(objHandle: HCkByteData;
    ch: Char) stdcall;
```

Appends a single byte.

### CkByteData.appendCharN

`Chilkat 11.7.0 · delphidll · CkByteData · appendCharN · method`

```pascal
procedure CkByteData_appendCharN(objHandle: HCkByteData;
    ch: Char;
    numTimes: Integer) stdcall;
```

Appends a single char N times. The equivalent of calling appendChar N times.

### CkByteData.appendEncoded

`Chilkat 11.7.0 · delphidll · CkByteData · appendEncoded · method`

```pascal
procedure CkByteData_appendEncoded(objHandle: HCkByteData;
    str: pbyte;
    encoding: pbyte) stdcall;
```

Appends binary data from an encoded string. The encoding can be specified as `hex`, `base64`, `url`, `quoted-printable`, `modBase64`, `base58`, or `base32`. The input string is decoded from the specified encoding and the binary data is appended to the calling object's content.

### CkByteData.appendEncodedW

`Chilkat 11.7.0 · delphidll · CkByteData · appendEncodedW · method`

```pascal
procedure CkByteData_appendEncodedW(objHandle: HCkByteData;
    str: PWideChar;
    encoding: PWideChar) stdcall;
```

To be documented soon...

### CkByteData.appendFile

`Chilkat 11.7.0 · delphidll · CkByteData · appendFile · method`

```pascal
function CkByteData_appendFile(objHandle: HCkByteData;
    path: pbyte): wordbool; stdcall;
```

Opens a file for binary read, appends the file contents, and closes the file.

### CkByteData.appendFileW

`Chilkat 11.7.0 · delphidll · CkByteData · appendFileW · method`

```pascal
function CkByteData_appendFileW(objHandle: HCkByteData;
    path: PWideChar): wordbool; stdcall;
```

Opens a file for binary read, appends the file contents, and closes the file.

### CkByteData.appendInt

`Chilkat 11.7.0 · delphidll · CkByteData · appendInt · method`

```pascal
procedure CkByteData_appendInt(objHandle: HCkByteData;
    intValue: Integer;
    littleEndian: wordbool) stdcall;
```

Appends a 32-bit signed integer (4 bytes) to the data already contained in the object. `littleEndian` determines whether the big endian or little endian byte ordering is used.

### CkByteData.appendRandom

`Chilkat 11.7.0 · delphidll · CkByteData · appendRandom · method`

```pascal
procedure CkByteData_appendRandom(objHandle: HCkByteData;
    numBytes: Integer) stdcall;
```

Appends `numBytes` random bytes to the data already contained within the object.

### CkByteData.appendShort

`Chilkat 11.7.0 · delphidll · CkByteData · appendShort · method`

```pascal
procedure CkByteData_appendShort(objHandle: HCkByteData;
    shortValue: SmallInt;
    littleEndian: wordbool) stdcall;
```

Appends a 16-bit signed integer (2 bytes) to the data already contained in the object. `littleEndian` determines whether the big endian or little endian byte ordering is used.

### CkByteData.appendStr

`Chilkat 11.7.0 · delphidll · CkByteData · appendStr · method`

```pascal
procedure CkByteData_appendStr(objHandle: HCkByteData;
    str: pbyte) stdcall;
```

Appends a null-terminated string to the data, without including the terminating null.

### CkByteData.appendStrW

`Chilkat 11.7.0 · delphidll · CkByteData · appendStrW · method`

```pascal
procedure CkByteData_appendStrW(objHandle: HCkByteData;
    str: PWideChar;
    charset: PWideChar) stdcall;
```

To be documented soon...

### CkByteData.byteSwap4321

`Chilkat 11.7.0 · delphidll · CkByteData · byteSwap4321 · method`

```pascal
procedure CkByteData_byteSwap4321(objHandle: HCkByteData) stdcall;
```

4321 byte swaps the data contained within the object.

### CkByteData.clear

`Chilkat 11.7.0 · delphidll · CkByteData · clear · method`

```pascal
procedure CkByteData_clear(objHandle: HCkByteData) stdcall;
```

Clears the CkByteData object of all data. The internal memory is deallocated. To clear without deallocating, call dropData instead.

### CkByteData.dropData

`Chilkat 11.7.0 · delphidll · CkByteData · dropData · method · since 9.5.0.91`

```pascal
procedure CkByteData_dropData(objHandle: HCkByteData) stdcall;
```

Sets the size of the data to 0. Does not deallocate the existing internal buffer. (This is a fast way of `clearing` the CkByteData object, such that the existing data remains in memory and is overwritten on the next append.)

If the SecureClear property is set to `True`, then the internal memory buffer is zeroed out before resetting the size to 0.

### CkByteData.encode

`Chilkat 11.7.0 · delphidll · CkByteData · encode · method`

```pascal
procedure CkByteData_encode(objHandle: HCkByteData;
    encoding: pbyte;
    str: HCkString) stdcall;
```

Encodes binary data according to the encoding requested. The encoding can be specified as `hex`, `base64`, `url`, `quoted-printable`, `modBase64`, `base58`, `base32`, `qp-`, `url_rfc1738`, `url_rfc2396`, or `url_rfc3986`.

### CkByteData.encodeW

`Chilkat 11.7.0 · delphidll · CkByteData · encodeW · method`

```pascal
procedure CkByteData_encodeW(objHandle: HCkByteData;
    encoding: PWideChar;
    str: HCkString) stdcall;
```

To be documented soon...

### CkByteData.ensureBuffer

`Chilkat 11.7.0 · delphidll · CkByteData · ensureBuffer · method`

```pascal
function CkByteData_ensureBuffer(objHandle: HCkByteData;
    expectedNumBytes: LongWord): wordbool; stdcall;
```

This method can be called to help optimize internal memory re-allocation. If, for example, many calls will be made to append data, and the total size is approximately known, then this method can be called to pre-allocate the internal buffer to the expected total size.

If the internal buffer is already larger than the `expectedNumBytes` then nothing happens. The existing internal buffer is kept.

Returns True for success, False for failure.

### CkByteData.getByte

`Chilkat 11.7.0 · delphidll · CkByteData · getByte · method`

```pascal
function CkByteData_getByte(objHandle: HCkByteData;
    byteIndex: LongWord): Byte; stdcall;
```

Returns the Nth byte of the binary data. The 1st byte is at index 0.

### CkByteData.getChar

`Chilkat 11.7.0 · delphidll · CkByteData · getChar · method`

```pascal
function CkByteData_getChar(objHandle: HCkByteData;
    byteIndex: LongWord): Char; stdcall;
```

Returns the Nth byte of the binary content as a `char`. The 1st byte is at index 0.

### CkByteData.getData

`Chilkat 11.7.0 · delphidll · CkByteData · getData · method`

```pascal
function CkByteData_getData(objHandle: HCkByteData): pbyte; stdcall;
```

Returns a pointer to the internal buffer. Be careful with this method because if additional data is appended, the data within the object may be relocated and the pointer may cease to be valid.

### CkByteData.getDataAt

`Chilkat 11.7.0 · delphidll · CkByteData · getDataAt · method`

```pascal
function CkByteData_getDataAt(objHandle: HCkByteData;
    byteIndex: LongWord): pbyte; stdcall;
```

Same as getData, except it gets a pointer to the data at a byte offset. (0 = the start of buffer)

### CkByteData.getEncoded

`Chilkat 11.7.0 · delphidll · CkByteData · getEncoded · method · since 9.5.0.47`

```pascal
function CkByteData_getEncoded(objHandle: HCkByteData;
    encoding: pbyte): pbyte; stdcall;
```

Returns the binary data as an encoded string. The encoding may be `base64`, `hex`, `quoted-printable` (or `qp`), `url`, `asc`, `url_rfc1738`, `url_rfc2396`, `url_rfc3986`, or `url_oauth`.

### CkByteData.getEncodedW

`Chilkat 11.7.0 · delphidll · CkByteData · getEncodedW · method`

```pascal
function CkByteData_getEncodedW(objHandle: HCkByteData;
    encoding: PWideChar): PWideChar; stdcall;
```

The utf-16 version of getEncoded.

### CkByteData.getInt

`Chilkat 11.7.0 · delphidll · CkByteData · getInt · method`

```pascal
function CkByteData_getInt(objHandle: HCkByteData;
    byteIndex: LongWord): Integer; stdcall;
```

Returns the 4-byte integer located at a specific byte index.

### CkByteData.getRange

`Chilkat 11.7.0 · delphidll · CkByteData · getRange · method`

```pascal
function CkByteData_getRange(objHandle: HCkByteData;
    byteIndex: LongWord;
    numBytes: LongWord): pbyte; stdcall;
```

Copies a range of bytes to a separate internal memory buffer and returns the pointer to the bytes. The returned pointer is only valid while the object exists. Also, any subsequent calls to getRange, getRangeStr, or to_s will invalidate the buffer.

### CkByteData.getSize

`Chilkat 11.7.0 · delphidll · CkByteData · getSize · method`

```pascal
function CkByteData_getSize(objHandle: HCkByteData): LongWord; stdcall;
```

Returns the number of bytes in the data buffer.

### CkByteData.getUInt

`Chilkat 11.7.0 · delphidll · CkByteData · getUInt · method`

```pascal
function CkByteData_getUInt(objHandle: HCkByteData;
    byteIndex: LongWord): LongWord; stdcall;
```

Returns the 4-byte unsigned integer located at a specific byte index.

### CkByteData.is7bit

`Chilkat 11.7.0 · delphidll · CkByteData · is7bit · method`

```pascal
function CkByteData_is7bit(objHandle: HCkByteData): wordbool; stdcall;
```

Returns `True` if all the bytes are in the range 0x00 to 0x7F.

### CkByteData.loadFile

`Chilkat 11.7.0 · delphidll · CkByteData · loadFile · method`

```pascal
function CkByteData_loadFile(objHandle: HCkByteData;
    path: pbyte): wordbool; stdcall;
```

Equivalent to clear() followed by appendFile().

### CkByteData.loadFileW

`Chilkat 11.7.0 · delphidll · CkByteData · loadFileW · method`

```pascal
function CkByteData_loadFileW(objHandle: HCkByteData;
    path: PWideChar): wordbool; stdcall;
```

To be documented soon...

### CkByteData.pad

`Chilkat 11.7.0 · delphidll · CkByteData · pad · method`

```pascal
procedure CkByteData_pad(objHandle: HCkByteData;
    blockSize: Integer;
    paddingScheme: Integer) stdcall;
```

Pads the data to a multiple of the `blockSize` using a cryptographic padding scheme specified by `paddingScheme`. The possible integer values for `paddingScheme` are the same as those listed for the PaddingScheme property of the CkCrypt2 class.

### CkByteData.removeChunk

`Chilkat 11.7.0 · delphidll · CkByteData · removeChunk · method`

```pascal
procedure CkByteData_removeChunk(objHandle: HCkByteData;
    startIndex: LongWord;
    numBytes: LongWord) stdcall;
```

Removes (discards) a range from the data.

### CkByteData.removeData

`Chilkat 11.7.0 · delphidll · CkByteData · removeData · method`

```pascal
function CkByteData_removeData(objHandle: HCkByteData): pbyte; stdcall;
```

Removes the data from the CkByteData object. The caller will receive a pointer to the memory buffer, and is responsible for deleting it.  
Example:  
unsigned char \*data = byteData.removeData();  
... do something with the data....  
delete \[\] data;

### CkByteData.replaceChar

`Chilkat 11.7.0 · delphidll · CkByteData · replaceChar · method`

```pascal
procedure CkByteData_replaceChar(objHandle: HCkByteData;
    existingByteValue: Byte;
    replacementByteValue: Byte) stdcall;
```

Replaces all occurrences of `existingByteValue` with `replacementByteValue`.

### CkByteData.saveFile

`Chilkat 11.7.0 · delphidll · CkByteData · saveFile · method`

```pascal
function CkByteData_saveFile(objHandle: HCkByteData;
    path: pbyte): wordbool; stdcall;
```

Saves the byte data to a file. If the file already exists, it will be overwritten.

### CkByteData.saveFileW

`Chilkat 11.7.0 · delphidll · CkByteData · saveFileW · method`

```pascal
function CkByteData_saveFileW(objHandle: HCkByteData;
    path: PWideChar): wordbool; stdcall;
```

To be documented soon...

### CkByteData.shorten

`Chilkat 11.7.0 · delphidll · CkByteData · shorten · method`

```pascal
procedure CkByteData_shorten(objHandle: HCkByteData;
    numBytes: LongWord) stdcall;
```

Discards N bytes from the end of the data.

### CkByteData.to_ws

`Chilkat 11.7.0 · delphidll · CkByteData · to_ws · method`

```pascal
function CkByteData_to_ws(objHandle: HCkByteData;
    charset: pbyte): PWideChar; stdcall;
```

To be documented soon...

### CkByteData.unpad

`Chilkat 11.7.0 · delphidll · CkByteData · unpad · method`

```pascal
procedure CkByteData_unpad(objHandle: HCkByteData;
    blockSize: Integer;
    paddingScheme: Integer) stdcall;
```

Unpads the data from a multiple of the `blockSize` to the original data size using a cryptographic padding scheme specified by `paddingScheme`. The possible integer values for `paddingScheme` are the same as those listed for the PaddingScheme property of the CkCrypt2 class.

## Deprecated members — do not use in new code

| Member | Kind | Deprecated in | Use instead |
|---|---|---|---|
| `append` | method | before 11.6.1 | — |
| `appendRange` | method | before 11.6.1 | — |
| `beginsWith` | method | before 11.6.1 | — |
| `equals` | method | before 11.6.1 | — |
| `findBytes` | method | before 11.6.1 | — |
| `getBytes` | method | before 11.6.1 | — |
| `preAllocate` | method | before 11.6.1 | — |

## Related classes

[`CkString`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/delphidll/classes/CkString.md)

