Using Delphi Inline Variables

One of the newer cool Delphi language features is inline variable support. I’m still a bit old school and like to declare my variables the old way, but the new method allows a similar approach to C# where variables can be declared within the procedure or function.

procedure HelloWorld;
var
  I: Integer;
begin
  i:= 55;
  ShowMessage (I.ToStrong);
end;

The above would be a typical procedure;

procedure HelloWorld;
begin
  var I: integer;
  i:= 55;
  ShowMessage (I.ToStrong);
end;

The above shows how I can now be declared within the procedure.

procedure HelloWorld;
begin
  var I: integer := 55;
  ShowMessage (I.ToStrong);
end;

Even better now, shown above, is the variable can be declared and initialized from within the procedure.

Leave a Comment

Scroll to Top