[Lazarus] Free Pascal and Lazarus learning center

Sven Barth pascaldragon at googlemail.com
Mon Feb 1 15:34:32 CET 2016


Am 01.02.2016 13:54 schrieb "Michael Van Canneyt" <michael at freepascal.org>:
>
>
>
> On Mon, 1 Feb 2016, Anthony Walter wrote:
>
>> Just a bit of information, my Cross.Codebot library has threading built
in
>> to the socket protocol implementations, so with regards to explaining it
I
>> could just show the source code or I could write it a again just to
>> demonstrate.
>>
>> With regards to complexity, I never define a new thread class, which is
the
>> typical way most people think about working with threads in Free Pascal.
>> Instead I have one thread class defined in my System unit, and you pass
it
>> your execute method along with an optional status handler. Your execute
is
>> called, the thread object is freed for you automatically, and you don't
>> need to declare a new type.
>>
>
> [snip]
>
>
>> procedure TDownloadForm.DownloadClick(Sender: TObject);
>> begin
>>  if FThread <> nil then
>>    Exit;
>>  FThread := TSimpleThread.Create(Download, DownloadStatus,
>> DownloadComplete);
>> end;
>
>
> This mechanism could easily be added as class static methods to TThread
> itself. It would make life easier for many simple cases.
>
> Class Procedure TThread.Spawn(MyProcedure,OnStatus,OnTerminate :
TThreadProcedure); static;
>
> Or "ExecuteInThread" instead of "Spawn".
>
> Would you care to enter this as a feature request ?

Current Delphis have something similar for anonymous functions already, so
we should use the same name, but with "of object" procvars instead (note:
the resulting thread class will be TAnonymousThread).

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160201/3422c332/attachment-0003.html>


More information about the Lazarus mailing list