BytesOf (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example demonstrates the use of BytesOf and WideBytesOf functions.

Code

Integer i;
TBytes ByteArray;

void __fastcall WriteBytes(TBytes BArray, TEdit* Edit)
{
  for (i=0;i<BArray.Length;i++)
  {
	  Edit->Text = Edit->Text + IntToStr(BArray[i]) + " ";
  }
}

void __fastcall TMainForm::btGetBytesClick(TObject *Sender)
{
  /* Convert the string into a byte array */
  ByteArray = BytesOf(Edit1->Text);

  /* Write the bytes in the second edit box */
  WriteBytes(ByteArray, Edit2);

  Edit1->Enabled = false;
  btGetBytes->Enabled = false;
  btGetWideBytes->Enabled = false;
}

void __fastcall TMainForm::btGetWideBytesClick(TObject *Sender)
{
  /* Convert the string into a byte array, with two bytes per character */
  ByteArray = WideBytesOf(Edit1->Text);

  /* Write the bytes in the second edit box */
  WriteBytes(ByteArray, Edit2);

  Edit1->Enabled = false;
  btGetBytes->Enabled = false;
  btGetWideBytes->Enabled = false;
}

Uses