For those who do not like inline vars or those that need to port Delphi code that introduced the unfortunate inline vars, me and Claude wrote Deinline: a de-inline-var-alyzer:
It de - inline var's your Object Pascal code... It puts the declaration firmly where it belongs. The attached version is 0.1. and considered Alpha, but it is already very useful.
You have to make a few changes yourself, though.
(Later this will be mitigated by type checking the inferenced var, code already testing here, no RTTI used)
Oh, and the code
stays Delphi compatible!
An example, given the following code:
{$apptype console}
{$ifdef fpc}{$mode objfpc}{$endif}
uses sysutils,classes;
procedure UseSomeInlineVars;
begin
var list := TStringlist.Create;
for var i := 0 to 10 do
begin
var s := 'string'+i.toString;
for var j := 0 to 9 do List.Add(Random(100).ToString);
end;
writeln(list.text);
List.free;
readln;
end;
begin
UseSomeInlineVars;
end.
Deinline will translate / de-mistify that into:
$ifdef fpc}{$mode objfpc}{$endif}
uses sysutils,classes;
procedure UseSomeInlineVars;
var
list: ; { TODO: add type }
i: ; { TODO: add type }
s: ; { TODO: add type }
j: ; { TODO: add type }
begin
list := TStringlist.Create;
for i := 0 to 10 do
begin
s := 'string'+i.toString;
for j := 0 to 9 do List.Add(Random(100).ToString);
end;
writeln(list.text);
List.free;
writeln;
end;
begin
UseSomeInlineVars;
end.
Let me know what you think.
There is good explanation - I hope - on how to use the program in the introductory header in the source and a more complex example is included.
And it is fully cross platform.