Content
property Content: TStream read write;
Example
procedure ScriptEvent(var Value: variant);
begin
if (Response <> nil) and (Response.Content <> nil) then
Value := Response.Content.Size
else
Value := 0;
end;
Usage
Gets or replaces the response content stream, with ownership controlled by FreeContentStream and nonempty text taking wire priority.
Additional Technical Info
Content is Velox's script name for native TWebResponse.ContentStream; it is not WebBroker's string Content property. Use ContentString for response text.
In a normal Velox REST action, the host assigns a new TMemoryStream before execution. Reading Content returns that actual mutable host-coordinated stream. Reads and writes share its bytes, size and position with native response producers such as file/report output. It is not a snapshot and is not thread-safe.
Assigning a different stream invokes WebBroker ownership logic:
- if
FreeContentStreamis true, the previous stream is freed immediately; - the new reference becomes both WebBroker's and Indy's content stream;
ContentLengthis set to the new stream'sSize(or string length when assigningnil); and- with
FreeContentStreamtrue, the response owns and later frees/releases the new stream.
Do not free a transferred stream afterward. If a stream must remain caller-owned, set FreeContentStream := False before assignment and keep it valid until sending finishes; the caller is then responsible for its eventual cleanup. Changing the flag does not resurrect a stream already freed by replacement.
This bridge has a material precedence difference from generic WebBroker documentation: Indy checks ContentText first. If ContentString is nonempty, its encoded text is sent and the stream is ignored. Otherwise Indy resets the stream position to zero and writes it. For HEAD, 1xx, 204 and 304 responses, no body bytes are written. Automatic sending then releases the response's content stream according to the Indy ownership flag.
Stream assignment can raise while freeing the old object, reading Size, converting a custom stream or allocating native state. A custom stream must support the Size and Position operations used during length calculation/sending. Do not assign the same stream to multiple owning responses. Test Response for nil.
External references
Created 2026-07-15