As you know, WITH keyword seems to be doomed as it's tagged as dangerous. The proposal is something like this:What would be the advantage over this?
with TForm2.Create(nil) do try AppLogger.LogForm(with); with.ShowModal finally with.Free end;
This would be similar as casting with "as" but with creating a variable on the fly.Actually Pascal "with" statement creates a pointer variable on the fly, what is missing that it gets a name. There is a very old Pascal dialect which supports such a safe with statement, I don't remember the name, you'll find it in FPC mailing list archive. It has been discussed many times.
(But again... that's not how Pascal works)
The only possible form I would see is with the "as"-keyword.
with TForm2.Create(nil) as myform do try AppLogger.LogForm(myform); myform.ShowModal finally myform.Free end;
I don't like it since it breaks the predeclaration of variables of Pascal.the only exception is made for exceptions :)
try
..
except
on e: exception do ...
end;
(need to be noted, this is not quite an exception to predeclaration rule, since the exception variable is predeclared ahead of the handling code. But it definitely looks like inline declaration, similar to C-ish for (var i=0...)
)