AsObject
property AsObject: TJSONObject read;
Example
procedure ScriptEvent(var Value: variant);
var
Generic: TJSONValue;
Document: TJSONObject;
begin
Document := TJSONObject.Create;
try
Generic := Document;
Generic.AsObject.AddString('status', 'ready');
Value := Document.AsString;
finally
Document.Free;
end;
end;
Usage
AsObject returns the same value as a borrowed TJSONObject after a checked runtime cast.
Additional Technical Info
AsObject performs the checked Delphi cast self as TJSONObject. It returns the receiver itself when the actual object is a TJSONObject or native subclass. It does not parse, clone, allocate or transfer ownership.
The result is an alias with the same lifetime. A script-created root is still freed exactly once by the script. A nested object returned from a parent remains borrowed; deletion, replacement or parent destruction invalidates every alias to it.
Arrays, Strings, numbers, Booleans and null nodes raise EInvalidCast. Check ValueType before access when input shape is not guaranteed. The property is constant-time, side-effect-free and unsynchronized; a nil or already freed receiver is invalid.
Use AsText when either structured kind is acceptable, or AsArray for an array-only view.
External references
- Embarcadero
EInvalidCast - Free Pascal
EInvalidCast- compatible checked-cast failure context.