I use this, derived from Indy's memorystream:
Type
// in a different (Indy) Unit:
TIdMemoryBufferStream = class(TCustomMemoryStream)
public
constructor Create(APtr: Pointer; ASize: TIdNativeInt);
function Write(const Buffer; Count: Longint): Longint; override;
end;
TIdCandelaMemoryBufferStream = class(TIdMemoryBufferStream)
procedure dosetpointer(aptr:pointer;asize:TIdNativeInt);
procedure write(io:TIdIOHandler;aptr:pointer;asize:TIdNativeInt);
end;
....
constructor TIdMemoryBufferStream.Create(APtr: Pointer; ASize: TIdNativeInt);
begin
inherited Create;
SetPointer(APtr, ASize);
end;
function TIdMemoryBufferStream.Write(const Buffer; Count: Longint): Longint;
var
LNumToCopy: Longint;
begin
Result := 0;
if (Position >= 0) and (Size > 0) and (Count > 0) then
begin
LNumToCopy := IndyMin(Size - Position, Count);
if LNumToCopy > 0 then
begin
System.Move(Buffer, Pointer(PtrUInt(Memory) + Position)^, LNumToCopy);
TIdStreamHelper.Seek(Self, LNumToCopy, soCurrent);
Result := LNumToCopy;
end;
end;
end;
{ TIdCandelaMemoryBufferStream }
procedure TIdCandelaMemoryBufferStream.dosetpointer(aptr: pointer;
asize: TIdNativeInt);
begin
SetPointer(aptr,asize);
position:=0;
end;
procedure TIdCandelaMemoryBufferStream.write(io:TIdIOHandler;aptr:pointer;asize:TIdNativeInt);
begin
SetPointer(aptr,asize);
position:=0;
if asize>0 then
io.Write(self,asize);
end;
It's from Indy, but more the utility routines, and used by but not connected to the rest of Indy.