GetAndInc
function GetAndInc(var aValue: variant): integer;
Example
procedure ScriptEvent(var Value: variant);
begin
Global1 := 41;
Value := GetAndInc(Global1); // Value = 41; Global1 = 42
end;
Usage
GetAndInc returns a Variant variable's current Integer value and then replaces the variable with that value plus one.
Parameters
| Name | Type | Description |
|---|---|---|
aValue | Variant, var | Assignable Variant storage. On success it is replaced with aValue + 1. |
Returns
The pre-increment value converted to a 32-bit Integer.
Additional Technical Info
GetAndInc implements a post-increment-like operation for a Variant variable: it first converts/copies the current value into a 32-bit Integer result, then evaluates Variant addition by one and stores that new Variant back into the same variable.
It was intended for variables such as Global1. It is a normal read/modify/write sequence, not an atomic counter primitive. The example is fictional and source-reviewed only.
Implementation order
Result := aValue;
aValue := aValue + 1;
The order matters:
- Delphi Variant-to-Integer conversion happens first.
- If that conversion fails or is out of range, the increment statement is not reached and
aValueremains unchanged. - If conversion succeeds, Variant
+is evaluated. - The resulting Variant is assigned back; a failure in addition/assignment propagates after the result calculation but before the function returns normally.
Accepted values and quirks
- Ordinary integral numeric Variants within the 32-bit range are the intended input.
- Floating and numeric-text Variants are subject to Delphi Variant conversion/rounding rules when assigned to the Integer result; do not assume truncation.
Null, error Variants, arrays, objects and nonnumeric text can raise conversion/operator errors. Process-global Variant settings can affect Null/conversion behaviour.- The stored post-increment Variant type follows Delphi Variant arithmetic and need not be identical to the original subtype.
- A starting value at or near an integer/Variant subtype limit can overflow, promote or raise according to the actual subtype and runtime settings.
- The
varparameter requires a variable. A literal, property-like expression or calculated expression cannot be used as the mutation target.
Concurrency and side effects
The supplied variable is mutated. No lock protects the read/convert/add/write sequence, so concurrent use of the same Global can lose increments. Use flow design or an external transactional/locking mechanism when uniqueness matters.
This helper does not persist a counter, log the change or coordinate between Velox processes.
Related entries
Incincrements supported typed integer storage but does not return the previous value and does not accept a Variant through its registered path.Decdecrements supported typed integer storage.
External references
Created 2026-07-15