Nick Hodges wrote:
> Brad White wrote: > >> What in the world for?? > > You already can do "using" in delphi: > > http://blogs.embarcadero.com/abauer/2008/09/25/38870 >
This was afraid of.
And do you think that that is a natural, clear, lean-and-mean, compact, readable, maintainable Delphi/Pascal syntax?
Even I know Allen's post since it was issued, and it is pretty straightforward how he did it, I need every time to stay and think how to write the so-called 'using'...
Also, there are enough quirks with the above kludge. Just one of them:
Try to compile the code bellow:
procedure TForm7.btn2Click(Sender: TObject);
function Foo: string; //simple function begin Result:='';
Obj.Using<TStringList>(TStringList.Create, procedure (List: TStringList) {syntax := yeck!} begin List.Add('Enter a value'); List.Add('which will be shown'); List.Add('if the "Using" works ok.'); Result:=InputBox('Testing "Using"', List.Text, ''); end); end;
begin ShowMessage(Foo); end;
It will not.
(The 'Result' variable cannot be "captured" by the anonymous procedure)
See http://qc.embarcadero.com/wc/qcmain.aspx?d=63369
and the (somewhat) related...
http://wings-of-wind.com/2010/02/11/community-pulse-delphis-killer-feature/ (The part about variables. Btw, the results of the poll are a little bit surprising, at least for me... :-))
Also you can implement a slightly different...
using <ref=type.constructor> do begin //code end;
....and have it only for objects.
my2c, HTH & Food for thought.
--
m. Th.
On the Wings of the Wind... http://wings-of-wind.com/