[fpc-devel] Question about Syntax: I there a reason for this design?

Boian Mitov mitov at mitov.com
Sun Sep 21 18:36:10 CEST 2014


  Hi Sam,

You can watch my CodeRage session last year explaining the huge advantages of the first syntax.
That being said, I consider it a design bug that local functions can’t be passed as anonymous methods in Delphi. There is no reason for that not to be done, except that they did not bother.
I hope if FPC implements anonymous methods, that they will also allow local functions to be passed, and outdo Delphi :-) .

With best regards,
Boian Mitov

-------------------------------------------------------
Mitov Software
www.mitov.com
-------------------------------------------------------

From: Samuel Herzog 
Sent: Saturday, September 20, 2014 11:10 PM
To: FPC developers' list 
Subject: [fpc-devel] Question about Syntax: I there a reason for this design?

I was looking at the following example in DXE7
http://delphiaball.co.uk/
procedure TFormThreading.Button1Click(Sender: TObject);
var
 aTask: ITask;
begin
 // not a thread safe snippet
 aTask := TTask.Create (procedure ()
   begin
     sleep (3000); // 3 seconds
     ShowMessage ('Hello');
   end);
 aTask.Start;
end;
I dislike this syntax and tried to write it this way because I think it's better readable code.
But it's not accepted.

procedure TFormThreading.Button1Click(Sender: TObject);
var
 aTask: ITask;
    procedure MyTask;
    begin
      sleep (3000); // 3 seconds
      ShowMessage ('Hello');
    endbegin
 // not a thread safe snippet
 aTask := TTask.Create(MyTask);
 aTask.Start;
end;I just wonder if there is a valuable reason to do it why my example is not allowed or would it be easy to make this available in free-pascal?

Thank you.
Sam







--------------------------------------------------------------------------------




--------------------------------------------------------------------------------
_______________________________________________
fpc-devel maillist  -  fpc-devel at lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20140921/cbd2a57e/attachment.html>


More information about the fpc-devel mailing list