New feature: Multi-variable initializationInitialize multiple variables of the same type with a single value. Works in var sections, typed constants, and inline var declarations. Gated by {$modeswitch multivarinit}, on by default in unleashed mode.
var sections{$mode unleashed}
var
a, b, c: integer = 42;
ok, done: boolean = false;
s1, s2: string = 'hello';
procedure Test;
var
x, y, z: integer = 10;
begin
writeln(x, ' ', y, ' ', z); // 10 10 10
end;
Each variable gets its own independent copy. Changing one does not affect the others.
Typed constantstype
TPoint = record x, y: integer; end;
const
MinX, MinY, MinZ: integer = 0;
Origin, Default: TPoint = (x: 0; y: 0);
Inline variablesWorks with both explicit type and type inference:
procedure Test;
begin
var p, q: integer := 99;
var i, j := 4; // both LongInt
var s1, s2 := 'hello'; // both String
end;
The initializer expression is evaluated once, then assigned to each variable. A function call on the right side executes exactly once:
function Init: integer;
begin
writeln('Init called');
result := 42;
end;
procedure Test;
begin
var a, b, c := Init; // Init called once
writeln(a, ' ', b, ' ', c);
end;
// output:
// Init called
// 42 42 42
IDE supportLazarus CodeTools updated to parse multi-variable typed constants, so code completion works for all names in the list.