BytesOf (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example demonstrates the use of BytesOf and WideBytesOf functions.

Code

var
  i: Integer;
  ByteArray: TBytes;

procedure WriteBytes(BArray: TBytes; Edit: TEdit);
begin
  for i := Low(BArray) to High(BArray) do
      Edit.Text := Edit.Text + IntToStr(BArray[i]) + ' ';
end;

procedure TMainForm.btGetBytesClick(Sender: TObject);
begin
  { 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;
end;

procedure TMainForm.btGetWideBytesClick(Sender: TObject);
begin
  { 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;
end;

Uses

Personal tools
Assistance