Suggestion Improvement : Inline Variables / Constants
Original Reporter info from Mantis: turrican
-
Reporter name: Enrique Fuentes
Original Reporter info from Mantis: turrican
- Reporter name: Enrique Fuentes
Description:
What do you think about this? Extracted form here : http://blog.marcocantu.com/blog/2018-october-inline-variables-delphi.html#FeedBack
Old style (keep) :
procedure Test;
var
I: Integer;
begin
I := 22;
ShowMessage (I.ToString);
end;
New style (new feature) :
procedure Test;
begin
var I, J: Integer;
I := 22;
j := I + 20;
ShowMessage (J.ToString);
end;
procedure Test; // declaration and initialization in a single statement
begin
var I: Integer := 22;
ShowMessage (I.ToString);
end;
procedure Test1; // multiple inline declarations (symbols declared when used)
begin
var I: Integer := 22;
var J: Integer := 22 + I;
var K: Integer := I + J;
ShowMessage (K.ToString);
end;
procedure Test2; // scope limited to local block
begin
var I: Integer := 22;
if I > 10 then
begin
var J: Integer := 3;
ShowMessage (J.ToString);
end
else
begin
var K: Integer := 3;
ShowMessage (J.ToString); // COMPILER ERROR: "Undeclared identifier: J"
end;
// J and K not accessible here
end;
I look at this code and I see a great feature. Can you study it?
Thanks!
Mantis conversion info:
- Mantis ID: 34486
- OS: All
- OS Build: All
- Platform: All