<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>
<div class="moz-cite-prefix">Am 21.09.2014 06:13, schrieb Jonas Maebe:</div>
<blockquote cite="mid:541EA4E2.5090509@elis.ugent.be" type="cite">
<pre wrap="">On 21/09/14 08:10, Samuel Herzog wrote:
</pre>
<blockquote type="cite">
<pre wrap="">But it's not accepted.
*procedure* TFormThreading.Button1Click(Sender: TObject);
*var*
aTask: ITask;
** procedure* *MyTask*;
*begin*
*sleep (3000); // 3 seconds*
*ShowMessage ('Hello');*
* end*
begin*
// 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?
</pre>
</blockquote>
<pre wrap="">In a perfect world: yes, it would be easy to make this available in FPC.
...
</pre>
</blockquote>
In fact its not that hard to do. With advanced records you can do something like this :<br/>
type<br/>
TCallbackType = (<br/>
FUNC,<br/>
NESTED,<br/>
METH<br/>
);<br/>
<br/>
TCallback = record<br/>
public type<br/>
TFunctionCallback = procedure;<br/>
TNestedCallback = procedure is nested;<br/>
TMethodCallback = procedure of object;<br/>
public<br/>
class operator implicit(callback : TFunctionCallback) : TCallback; inline;<br/>
class operator implicit(callback : TNestedCallback) : TCallback; inline;<br/>
class operator implicit(callback : TMethodCallback) : TCallback; inline;<br/>
<br/>
procedure call; inline;<br/>
strict private<br/>
case callbackType : TCallbackType of<br/>
TCallbackType.FUNC : (<br/>
func : TFunctionCallback;<br/>
);<br/>
TCallbackType.NESTED : (<br/>
nested : TNestedCallback;<br/>
);<br/>
TCallbackType.METH : (<br/>
meth : TMethodCallback;<br/>
);<br/>
end; <br/>
<br/>
The only drawbacks I see are:<br/>
overhead for the actual call<br/>
supporting multiple parameters(you can do somthing like TCallback<T1>, TCallback<T1, T2>,... sill not ideal but it works)<br/>
</div></div></body></html>