DeleteValue
procedure DeleteValue(const aValue: TJSONValue);
Example
procedure ScriptEvent(var Value: variant);
var
Values: TJSONArray;
Added: TJSONValue;
begin
Values := TJSONArray.Create;
try
Added := Values.AddString('temporary');
Values.DeleteValue(Added);
Added := nil; // The node was freed by the array.
Value := Values.Count;
finally
Values.Free;
end;
end;
Usage
DeleteValue finds a child by object identity, then deletes and frees it, raising when it is absent.
Additional Technical Info
DeleteValue calls the backing list's IndexOf and then delegates to indexed deletion. Matching uses the exact object reference, not JSON content, name or IsEqual. A separate clone with identical text is not a match.
The array owns a matching node and frees it during deletion. Set any caller variable holding that node to nil and discard descendant references. Do not call Free before or after this method.
If aValue is nil, belongs to another array, was already removed or is merely an equal clone, IndexOf returns -1; indexed deletion then raises a list-range error. The method has no harmless not-found path. Confirm identity by iterating Items before calling when absence is possible.
External references
- Embarcadero
TList.IndexOf - Embarcadero
TObjectList.Delete - Free Pascal
TObjectList- compatible identity/ownership context.