As dummzeuch says, you could write your own routine. However, I would prefer one with a signature something like: procedure AssignIntegers(AValue, ATargetArray);
. And ideally call the routine with: AssignInteger(99, [X, Y, Z]);
.
Unfortunately the ideal option does not work, but the following procedure is close enough and should suffice. It works by taking pointers to the integers that need to be assigned.
procedure AssignIntegers(AValue: Integer; const ATargets: array of PInteger);
var
I: Integer;
begin
for I := Low(ATargets) to High(ATargets) do
ATargets[I]^ := AValue;
end;
The following DUnit test case demonstrates that it works. You can even keep an array of these integer pointers handy to reassign at any time.
type
TArrayPInteger = array of PInteger;
procedure TDelphiTests.TestAssignIntegers;
var
X,Y,Z: Integer;
LGroup: TArrayPInteger;
begin
AssignIntegers(1, [@X, @Y, @Z]); { Pass open arrray using addresses of integers to initialise }
CheckEquals(1, X);
CheckEquals(1, Y);
CheckEquals(1, Z);
LGroup := TArrayPInteger.Create(@X, @Y); { Handy technique to initialise dynamic arrays }
AssignIntegers(2, LGroup);
CheckEquals(2, X);
CheckEquals(2, Y);
CheckEquals(1, Z); { Not part of group }
end;
WARNING
The only real drawback is that you lose type-checking. The compiler won't prevent you from passing the address of non-integer types. This can lead to corrupting other structures' data or access violations.