For completeness, you were on the right track.
It is OK to declare as Tstream, but then you need to use it like this:
{$mode objfpc}
uses classes;
// access to memorystream specific methods and properties from TStream;
var
data:Tstream;
begin
data := TmemoryStream.Create;
// either soft cast
(data as TmemoryStream).SetSize(8);
// or hard cast
TMemoryStream(Data).SetSize(8);
Data.free;
end.
That way you can still assign the data stream to any other Tstream descendant.
Methods and properties that are shared with the ancestor class (read/write) do not need a cast.