Here is an updated xtea.pas that uses streams by default with overloaded methods for strings. The formatting and class style has also been Delphi'ed. The sample code hasn't changed except the call to InitKey is now a write to the Key property.

Tested and all works fine. This has been an interesting challenge.

[pascal]unit xtea;

interface

uses
Classes, SysUtils;

type
TKey128 = array [0..3] of LongWord;
TBlock64 = array [0..1] of LongWord;

TXTea = class(TObject)
private
FKey: TKey128;
procedure CipherXTea(var Block: TBlock64);
procedure DecipherXTea(var Block: TBlock64);
function GetKey: String;
procedure SetKey(const Value: String);
public
constructor Create;
destructor Destroy; override;
procedure Burn;
function Encrypt(Input, Output: TStream; InputSize: LongWord): LongWord; overload;
function Encrypt(const Input: String; Output: TStream): LongWord; overload;
procedure Decrypt(Input, Output: TStream; InputSize: LongWord); overload;
function Decrypt(Input: TStream; Count: LongWord): String; overload;
function PaddedSize(Size: LongWord): LongWord;
property Key: String read GetKey write SetKey;
end;

implementation

const
DELTA = $9e3779b9;
XTEA_BLANK: TBlock64 = (0, 0);
XTEA_BURN: TKey128 =(0, 0, 0, 0);

function Min(A, B: Integer): Integer;
begin
Result := A;
if B < A then
Result := B;
end;

constructor TXTea.Create;
begin
inherited;
Burn;
end;

destructor TXTea.Destroy;
begin
Burn;
inherited;
end;

procedure TXTea.Burn;
begin
FKey := XTEA_BURN;
end;

procedure TXTea.DecipherXTea(var Block: TBlock64);
var
Index: Integer;
Sum: Longword;
begin
Sum := $C6EF3720;

for Index := 0 to 31 do
begin
Dec(Block[1], ((Block[0] shl 4 xor Block[0] shr 5) + Block[0]) xor (Sum + FKey[Sum shr 11 and 3]));
Dec(Sum, DELTA);
Dec(Block[0], ((Block[1] shl 4 xor Block[1] shr 5) + Block[1]) xor (Sum + FKey[Sum and 3]));
end;
end;

procedure TXTea.Decrypt(Input, Output: TStream; InputSize: LongWord);
var
Index: LongWord;
Block: TBlock64;
begin
if Key = '' then
raise Exception.Create('Error: You must set a key');

Index := 0;
while Index < InputSize do
try
Block := XTEA_BLANK;
Input.Read(Block, SizeOf(Block));
DecipherXTea(Block);
Output.Write(Block, SizeOf(Block));
Inc(Index, SizeOf(Block));
except
raise;
end;
end;

function TXTea.Decrypt(Input: TStream; Count: LongWord): String;
var
Stream: TMemoryStream;
begin
Stream := TMemoryStream.Create;
try
Decrypt(Input, Stream, Count);
Result := PChar(Stream.Memory);
finally
Stream.Free;
end;
end;

function TXTea.PaddedSize(Size: LongWord): LongWord;
begin
Result := (Size + (SizeOf(TBlock64) - 1)) and (not (SizeOf(TBlock64) - 1));
end;

procedure TXTea.CipherXTea(var Block: TBlock64);
var
Sum: LongWord;
Index: Integer;
begin
Sum := 0;

for Index := 0 to 31 do
begin
Inc(Block[0], ((Block[1] shl 4 xor Block[1] shr 5) + Block[1]) xor (Sum + FKey[Sum and 3]));
Inc(Sum, DELTA);
Inc(Block[1], ((Block[0] shl 4 xor Block[0] shr 5) + Block[0]) xor (Sum + FKey[Sum shr 11 and 3]));
end;
end;

function TXTea.Encrypt(Input, Output: TStream; InputSize: LongWord): LongWord;
var
Index: LongWord;
Block: TBlock64;
begin
if Key = '' then
raise Exception.Create('Error: You must set a key');

Result := PaddedSize(InputSize);

Index := 0;
while Index < InputSize do
try
Block := XTEA_BLANK;
Input.Read(Block, Min(SizeOf(Block), InputSize - Index));
CipherXTea(Block);
Output.Write(Block, SizeOf(Block));
Inc(Index, SizeOf(Block));
except
raise;
end;
end;

function TXTea.Encrypt(const Input: String; Output: TStream): LongWord;
var
Stream: TMemoryStream;
begin
Stream := TMemoryStream.Create;
try
Stream.Write(Input[1], Length(Input) + 1);
Stream.Position := 0;
Result := Encrypt(Stream, Output, Stream.Size);
finally
Stream.Free;
end;
end;

function TXTea.GetKey: String;
begin
Result := PChar(@FKey);
end;

procedure TXTea.SetKey(const Value: String);
begin
Burn;
Move(Value[1], FKey, Min(Length(Value), SizeOf(FKey)));
end;

end.[/pascal]