function BufferToDisplay(const mBuffer; mSize: Integer): string;
var
I: Integer;
begin
Result := '';
for I := 0 to mSize - 1 do
try
Result := Result + IntToHex(TByteArray(mBuffer)[I], 2);
except
Result := '';
Exit;
end;
end;
function DisplayToBuffer(mDisplay: string; var mBuffer; mSize: Integer): Boolean;
var
I: Integer;
begin
Result := False;
for I := 0 to mSize - 1 do
try
TByteArray(mBuffer)[I] := StrToIntDef('$' + Copy(mDisplay, I * 2 + 1, 2), 0);
except
Exit;
end;
Result := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
I := StrToIntDef(Edit1.Text, 0);
Edit2.Text := BufferToDisplay(I, SizeOf(I));
end;
procedure TForm1.Button2Click(Sender: TObject);
var
I: Integer;
begin
DisplayToBuffer(Edit2.Text, I, SizeOf(I));
Edit1.Text := IntToStr(I);
end;