I have 10 double variables I would like to initialize with the value 0. They are unstructured and not part of an array by design.
procedure Initialize;
var
a1, a2, a3, a4, a5, b1, b2, b3, b4, b5: Double;
begin
a1 := 0;
a2 := 0;
a3 := 0;
a4 := 0;
a5 := 0;
b1 := 0;
b2 := 0;
b3 := 0;
b4 := 0;
b5 := 0;
end;
To refactor that piece of code, I'm introducing a helper method AssignValue.
procedure Initialize;
var
a1, a2, a3, a4, a5, b1, b2, b3, b4, b5: Double;
begin
AssignValue(0,a1);
AssignValue(0,a2);
...
end;
procedure AssignValue(value: Double; var target: Double);
begin
target:= value;
end;
How do I write a more general AssignValue
procedure that takes an arbitrary number of arguments and make the call AssignValue(0,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5)
possible?
Bonus question: How do you write that procedure so that it takes into account double
or int
reference in any order, assuming value: Int
as first parameter.