[Feature Request - New syntax : Declare local variables with value - https://quality.

[Feature Request - New syntax : Declare local variables with value - https://quality.embarcadero.com/browse/RSP-14867]

Since we can already do this (for global variables):
var
Variable: Type = Value;

And this :
procedure Example;
const
Symbol: Type = Value;
begin
// code
end;

How about this syntax?
procedure Example;
var
Variable: Type = value;
begin
// code
end;

This would only initialize the variables that are specifically assigned a starting value.

When applied to managed types (string, interface), this syntax can also avoid the otherwise automatic cleaning of the stack, since this syntax already assigns a value to these variables. I would expect an initialization each time the function is called.

(In this regard, it's a bit similar to default argument values - https://quality.embarcadero.com/browse/RSP-13289)

Dynamic arrays can already be initialized from declaration since XE7, I think it could get expanded to other types as well :D

Comments