<html>
<head>
<title>AsyncCalls - asynchronous function calls</title>
<style type="text/css">
<!--
a {
text-decoration: none;
color: #4444ff;
}
a:hover {
text-decoration: underline;
color: #ff0000;
}
body {
margin: 10px;
padding: 0px;
}
body, p, td, table, li, ol, ul {
font-family: verdana, arial, helvetica;
font-size: 12px;
line-height: 13pt;
}
p {
font-size: 12px;
line-height: 13pt;
text-align: justify;
}
h1, h2, h3, h4, h5, h6 {
text-align: left;
font-weight: normal;
font-family: arial, verdana, helvetica;
}
h3 { font-weight: bold; }
h3.Example { position: relative; left: 20px; }
ol {
margin-top: 5px;
margin-bottom: 5px;
}
div.code {
font-family: "Courier New"; font-size: 10pt;
border: 1px dotted gray;
padding-left: 2px;
padding-right: 2px;
background-color: #f0f0e0;
position: relative;
left: 20px;
width: 98%;
}
.center { text-align: center; }
.right { text-align: right; }
.left { text-align: left; }
.block { text-align: justify; }
.u0 { color: #FF0000; }
.u1 { font-style: italic; color: #008000; }
.u2 { color: #0000FF; }
.u3 { color: #008000; }
.u4 { color: #000000; }
.u5 { font-weight: bold; color: #000080; }
.u6 { color: #000080; }
.u7 { color: #000000; }
.u8 { color: #0000FF; }
.u9 { color: #000000; }
.u10 { color: #0000FF; }
// -->
</style>
</head>
<body bgcolor="white">
<h1>AsyncCalls - asynchronous function calls</h1>
<p>With AsyncCalls you can execute multiple functions at the same time and synchronize them at every point in
the function or method that started them. This allows you to execute time consuming code whos result is needed
at a later time in a different thread. While the asynchronous function is executed the caller function can do
other tasks.</p>
<p>The AsyncCalls unit offers a variety of function prototypes to call asynchronous functions. There are functions
that can call asynchron functions with one single parameter of the type: TObject, Integer, AnsiString, WideString,
IInterface, Extended and Variant. Another function allows you to transfer a user defined value type (record) to the asynchron
function where it can be modify. And there are functions that can call asynchron functions with a variable number of
arguments. The arguments are specified in an <span class="u5">const array of const</span> and are automatically
mapped to normal function arguments.</p>
<p>Inlined VCL/main thread synchronization is supported starting with version 2.0. With this you can implement
the code that calls a VCL function directly in your thread method without having to use a helper method and
TThread.Synchronize. You have full access to all local variables.<br/>
Version 2.9 introduces the TAsyncCalls class that utilizes generics and anonymous methods (Delphi 2009 or newer).</p>
<h2>Download</h2>
<p><a href="AsyncCalls.zip">AsyncCalls.zip</a> Version 2.96 30 KB)</p>
<h2>License</h2>
<p>The AsyncCalls unit is licensed under the <a href="http://www.mozilla.org/MPL/MPL-1.1.html">Mozilla Public Licence ("MPL") version 1.1</a>.
<h2>Installation</h2>
<p>Extract the AsyncCalls.zip to a directory of your choice. Add the AnyncCalls.pas unit to your project and uses statements.</p>
<h2>Requirements</h2>
<p>Works with Delphi 5, 6, 7, 2005, BDS/Turbo 2006 and RAD Studio 2007, 2009, 2010 and XE</p>
<h2>Changelog</h2>
<p>
<ul>
<li><b>Version: 2.96 (2010-09-12)</b>:<br/>
Fixed: CoInitialize call was missing<br/>
</li>
<li><b>Version: 2.95 (2010-09-12)</b>:<br/>
Added: Support for RAD Studio XE<br/>
Added: Support for UnicodeString<br/>
</li>
<li><b>Version: 2.92 (2009-08-30)</b>:<br/>
Added: Support for RAD Studio 2010<br/>
Restored: Delphi 2009 Update 1 fixed the compiler bug. All generic methods are now available.<br/>
</li>
<li><b>Version 2.91 (2008-09-29)</b>:<br/>
Fixed: All generic methods are now disabled due to an internal compiler error in Delphi 2009<br/>
</li>
<li><b>Version 2.9 (2008-09-27)</b>:<br/>
Fixed: Window message handling<br/>
Added: Delphi 2009 support with generics and anonymous methods<br/>
Added: AsyncCall(Runnable: IAsyncRunnable)<br/>
</li>
<li><b>Version 2.21 (2008-05-14)</b>:<br/>
Fixed: Bug in AsyncMultiSync<br/>
</li>
<li><b>Version 2.2 (2008-05-12)</b>:<br/>
Fixed: Bugs in main thread AsyncMultiSync implementation<br/>
Added: Delphi 5 support<br/>
</li>
<li><b>Version 2.1 (2008-05-06)</b>:<br/>
Added: Delphi 6 support<br/>
Added: Support for "Exit;" in the MainThread block<br/>
Fixed: Exception handling for Delphi 6, 7 and 2005<br/>
Fixed: EBX, ESI and ESI are now copied into the synchronized block (Self-Pointer)<br/>
</li>
<li><b>Version 2.0 (2008-05-04)</b>:<br/>
Added: EnterMainThread/LeaveMainThread<br/>
Added: LocalVclCall, LocalAsyncVclCall, MsgAsyncMultiSync<br/>
Added: LocalAsyncExec, AsyncExec<br/>
Added: IAsyncCall.ForceDifferentThread<br/>
Fixed: Exception handling<br/>
Removed: Delphi 5 and 6 support<br/>
<li><b>Version 1.2 (2008-02-10)</b>:<br/>
Added CoInitialize for the threads<br/>
LocalAsyncCall function<br/>
Exception handling<br/>
</li>
<li><b>Version 1.1 (2007-08-14)</b>:<br/>
Workaround for TThread.Resume bug<br />
</li>
<li><b>Version 1.0 (2006-12-23)</b>:<br/>
Fixed: Exception where Thread was destroyed while the finalization code accessed it.</li>
</ul>
</p>
<h2>Example</h2>
<div class="code">
<!--<span class="u5">function</span> <span class="u4">TForm1</span><span class="u9">.</span><span class="u4">DoSomething</span><span class="u9">(</span><span class="u4">Value</span><span class="u9">:</span> <span class="u4">TObject</span><span class="u9">):</span> <span class="u4">Integer</span><span class="u9">;</span>
<br><span class="u5">begin</span>
<br> <span class="u4">Result</span> <span class="u9">:=</span> <span class="u6">0</span><span class="u9">;</span>
<br><span class="u5">end</span><span class="u9">;</span>
<br>
<br>--><span class="u5">procedure</span> <span class="u4">TForm1</span><span class="u9">.</span><span class="u4">Button3Click</span><span class="u9">(</span><span class="u4">Sender</span><span class="u9">:</span> <span class="u4">TObject</span><span class="u9">);</span>
<br><span class="u5">var</span>
<br> <span class="u4">Value</span><span class="u9">:</span> <span class="u4">Integer</span><span class="u9">;</span>
<br><span class="u5">begin</span>
<!--<br> <span class="u4">TAsyncCalls</span><span class="u9">.</span><span class="u4">Invoke</span><span class="u9"><</span><span class="u4">TObject</span><span class="u9">>(</span><span class="u4">DoSomething</span><span class="u9">,</span> <span class="u5">nil</span><span class="u9">);</span>
<br>-->
<br> <span class="u4">TAsyncCalls</span><span class="u9">.</span><span class="u4">Invoke</span><span class="u9">(</span><span class="u5">procedure</span>
<br> <span class="u5">begin</span>
<br> <span class="u4">Value</span> <span class="u9">:=</span> <span class="u6">10</span><span class="u9">;</span>
<br> <span class="u4">TAsyncCalls</span><span class="u9">.</span><span class="u4">VCLInvoke</span><span class="u9">(</span><span class="u5">procedure</span>
<br> <span class="u5">begin</span>
<br> <span class="u4">ShowMessage</span><span class="u9">(</span><span class="u8">'The value may not equal 10: '</span> <span class="u9">+</span> <span class="u4">IntToStr</span><span c