亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? asynccalls.pas

?? Asyncronous call of delphi functions and procedures.
?? PAS
?? 第 1 頁 / 共 5 頁
字號:
{**************************************************************************************************}
{                                                                                                  }
{ Asynchronous function calls utilizing multiple threads.                                          }
{                                                                                                  }
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the    }
{ License at http://www.mozilla.org/MPL/                                                           }
{                                                                                                  }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF   }
{ ANY KIND, either express or implied. See the License for the specific language governing rights  }
{ and limitations under the License.                                                               }
{                                                                                                  }
{ The Original Code is AsyncCalls.pas.                                                             }
{                                                                                                  }
{ The Initial Developer of the Original Code is Andreas Hausladen.                                 }
{ Portions created by Andreas Hausladen are Copyright (C) 2006-2008 Andreas Hausladen.             }
{ All Rights Reserved.                                                                             }
{                                                                                                  }
{ Contributor(s):                                                                                  }
{                                                                                                  }
{**************************************************************************************************}
{                                                                                                  }
{ Version: 2.91 (2008-09-29)                                                                       }
{   Fixed: All generic methods are now disabled due to an internal compiler error in Delphi 2009   }
{                                                                                                  }
{ Version: 2.9 (2008-09-27)                                                                        }
{   Fixed: Window message handling                                                                 }
{   Added: Delphi 2009 support with generics and anonymous methods                                 }
{   Added: AsyncCall(Runnable: IAsyncRunnable)                                                     }
{                                                                                                  }
{ Version: 2.21 (2008-05-14)                                                                       }
{   Fixed: Fixed bug in AsyncMultiSync                                                             }
{                                                                                                  }
{ Version: 2.2 (2008-05-12)                                                                        }
{   Fixed: Bugs in main thread AsyncMultiSync implementation                                       }
{   Added: Delphi 5 support                                                                        }
{                                                                                                  }
{ Version: 2.1 (2008-05-06)                                                                        }
{   Added: Delphi 6 support                                                                        }
{   Added: Support for "Exit;" in the MainThread block                                             }
{   Fixed: Exception handling for Delphi 6, 7 and 2005                                             }
{   Fixed: EBX, ESI and EDI weren't copied into the synchronized block (e.g. used for Self-Pointer)}
{                                                                                                  }
{ Version: 2.0 (2008-05-04)                                                                        }
{   Added: EnterMainThread/LeaveMainThread                                                         }
{   Added: LocalVclCall, LocalAsyncVclCall, MsgAsyncMultiSync                                      }
{   Added: LocalAsyncExec, AsyncExec                                                               }
{   Added: IAsyncCall.ForceDifferentThread                                                         }
{   Fixed: Exception handling                                                                      }
{   Removed: Delphi 5 and 6 support                                                                }
{                                                                                                  }
{ Version: 1.2 (2008-02-10)                                                                        }
{   Added: CoInitialize                                                                            }
{   Added: LocalAsynCall() function                                                                }
{                                                                                                  }
{ Version: 1.1 (2007-08-14)                                                                        }
{   Fixed: Workaround for TThread.Resume bug                                                       }
{                                                                                                  }
{ Version: 1.0 (2006-12-23)                                                                        }
{   Initial release                                                                                }
{**************************************************************************************************}
{$A+,B-,C-,D-,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W+,X+,Y+,Z1}

unit AsyncCalls;

{$DEFINE DEBUG_ASYNCCALLS}

interface

{$IFNDEF CONDITIONALEXPRESSIONS}
  {$IFDEF VER130}
    {$DEFINE DELPHI5}
  {$ELSE}
    'Your compiler version is not supported'
  {$ENDIF}
{$ELSE}
  {$IFDEF VER140}
    {$DEFINE DELPHI6}
    {.$MESSAGE ERROR 'Your compiler version is not supported'}
  {$ELSE}
    {$DEFINE DELPHI7_UP}
  {$ENDIF}

  {$WARN SYMBOL_PLATFORM OFF}
  {$WARN UNIT_PLATFORM OFF}
  {$IF CompilerVersion >= 15.0}
    {$WARN UNSAFE_TYPE OFF}
    {$WARN UNSAFE_CODE OFF}
    {$WARN UNSAFE_CAST OFF}
  {$IFEND}

  {$IF CompilerVersion >= 18.0}
    {$DEFINE SUPPORTS_INLINE}
  {$IFEND}

  {$IF CompilerVersion >= 20.0}
    {$DEFINE DELPHI2009_UP}
  {$IFEND}
{$ENDIF}

{$IFDEF DEBUG_ASYNCCALLS}
  {$D+,C+}
{$ENDIF DEBUG_ASYNCCALLS}

uses
  Windows, Messages, SysUtils, Classes, Contnrs, ActiveX, SyncObjs;

type
  {$IFNDEF CONDITIONALEXPRESSIONS}
  INT_PTR = Integer;
  IInterface = IUnknown;
  {$ELSE}
    {$IF not declared(INT_PTR)}
  INT_PTR = Integer;
    {$IFEND}
  {$ENDIF}

  TAsyncIdleMsgMethod = procedure of object;

  TCdeclFunc = Pointer; // function(Arg1: Type1; Arg2: Type2; ...); cdecl;
  TCdeclMethod = TMethod; // function(Arg1: Type1; Arg2: Type2; ...) of object; cdecl;
  TLocalAsyncProc = function: Integer;
  TLocalVclProc = function(Param: INT_PTR): INT_PTR;
  TLocalAsyncProcEx = function(Param: INT_PTR): INT_PTR;
  //TLocalAsyncForLoopProc = function(Index: Integer; SyncLock: TCriticalSection): Boolean;

  TAsyncCallArgObjectProc = function(Arg: TObject): Integer;
  TAsyncCallArgIntegerProc = function(Arg: Integer): Integer;
  TAsyncCallArgStringProc = function(const Arg: AnsiString): Integer;
  TAsyncCallArgWideStringProc = function(const Arg: WideString): Integer;
  TAsyncCallArgInterfaceProc = function(const Arg: IInterface): Integer;
  TAsyncCallArgExtendedProc = function(const Arg: Extended): Integer;
  TAsyncCallArgVariantProc = function(const Arg: Variant): Integer;

  TAsyncCallArgObjectMethod = function(Arg: TObject): Integer of object;
  TAsyncCallArgIntegerMethod = function(Arg: Integer): Integer of object;
  TAsyncCallArgStringMethod = function(const Arg: AnsiString): Integer of object;
  TAsyncCallArgWideStringMethod = function(const Arg: WideString): Integer of object;
  TAsyncCallArgInterfaceMethod = function(const Arg: IInterface): Integer of object;
  TAsyncCallArgExtendedMethod = function(const Arg: Extended): Integer of object;
  TAsyncCallArgVariantMethod = function(const Arg: Variant): Integer of object;

  TAsyncCallArgObjectEvent = procedure(Arg: TObject) of object;
  TAsyncCallArgIntegerEvent = procedure(Arg: Integer) of object;
  TAsyncCallArgStringEvent = procedure(const Arg: AnsiString) of object;
  TAsyncCallArgWideStringEvent = procedure(const Arg: WideString) of object;
  TAsyncCallArgInterfaceEvent = procedure(const Arg: IInterface) of object;
  TAsyncCallArgExtendedEvent = procedure(const Arg: Extended) of object;
  TAsyncCallArgVariantEvent = procedure(const Arg: Variant) of object;

  TAsyncCallArgRecordProc = function(var Arg{: TRecordType}): Integer;
  TAsyncCallArgRecordMethod = function(var Arg{: TRecordType}): Integer of object;
  TAsyncCallArgRecordEvent = procedure(var Arg{: TRecordType}) of object;

  EAsyncCallError = class(Exception);

  IAsyncCall = interface
    { Sync() waits until the asynchronous call has finished and returns the
      result value of the called function if that exists. }
    function Sync: Integer;

    { Finished() returns True if the asynchronous call has finished. }
    function Finished: Boolean;

    { ReturnValue() returns the result of the asynchronous call. It raises an
      exception if called before the function has finished. }
    function ReturnValue: Integer;

    { ForceDifferentThread() tells AsyncCalls that the assigned function must
      not be executed in the current thread. }
    procedure ForceDifferentThread;
  end;

  { *** Internal interface. Do not use it *** }
  IAsyncCallEx = interface
    ['{A31D8EE4-17B6-4FC7-AC94-77887201EE56}']
    function GetEvent: THandle;
    function SyncInThisThreadIfPossible: Boolean;
  end;

  IAsyncRunnable = interface
    ['{1A313BBD-0F89-43AD-8B57-BBA3205F4888}']
    procedure AsyncRun;
  end;


{ SetMaxAsyncCallThreads() controls how many threads can be used by the
  async call thread pool. The thread pool creates threads when they are needed.
  Allocated threads are not destroyed until the application has terminated, but
  they are suspended if not used. }
procedure SetMaxAsyncCallThreads(MaxThreads: Integer);
{ GetMaxAsyncCallThreads() returns the maximum number of threads that can
  exist in the thread pool. }
function GetMaxAsyncCallThreads: Integer;


{ AsyncCall() executes the given function/procedure in a separate thread. The
  result value of the asynchronous function is returned by IAsyncCall.Sync() and
  IAsyncCall.ReturnValue().
  The AsyncExec() function calls the IdleMsgMethod in a loop, while the async.
  method is executed.

Example:
  function FileAgeAsync(const Filename: string): Integer;
  begin
    Result := FileAge(Filename);
  end;

  var
    a: IAsyncCall;
  begin
    a := AsyncCall(FileAgeAsync, 'C:\Windows\notepad.exe');
    // do something
    Age := a.Sync;
  end;
}
function AsyncCall(Proc: TAsyncCallArgObjectProc; Arg: TObject): IAsyncCall; overload;
function AsyncCall(Proc: TAsyncCallArgIntegerProc; Arg: Integer): IAsyncCall; overload;
function AsyncCall(Proc: TAsyncCallArgStringProc; const Arg: AnsiString): IAsyncCall; overload;
function AsyncCall(Proc: TAsyncCallArgWideStringProc; const Arg: WideString): IAsyncCall; overload;
function AsyncCall(Proc: TAsyncCallArgInterfaceProc; const Arg: IInterface): IAsyncCall; overload;
function AsyncCall(Proc: TAsyncCallArgExtendedProc; const Arg: Extended): IAsyncCall; overload;
function AsyncCallVar(Proc: TAsyncCallArgVariantProc; const Arg: Variant): IAsyncCall; overload;

function AsyncCall(Method: TAsyncCallArgObjectMethod; Arg: TObject): IAsyncCall; overload;
function AsyncCall(Method: TAsyncCallArgIntegerMethod; Arg: Integer): IAsyncCall; overload;
function AsyncCall(Method: TAsyncCallArgStringMethod; const Arg: AnsiString): IAsyncCall; overload;
function AsyncCall(Method: TAsyncCallArgWideStringMethod; const Arg: WideString): IAsyncCall; overload;
function AsyncCall(Method: TAsyncCallArgInterfaceMethod; const Arg: IInterface): IAsyncCall; overload;
function AsyncCall(Method: TAsyncCallArgExtendedMethod; const Arg: Extended): IAsyncCall; overload;
function AsyncCallVar(Method: TAsyncCallArgVariantMethod; const Arg: Variant): IAsyncCall; overload;

function AsyncCall(Method: TAsyncCallArgObjectEvent; Arg: TObject): IAsyncCall; overload;
function AsyncCall(Method: TAsyncCallArgIntegerEvent; Arg: Integer): IAsyncCall; overload;
function AsyncCall(Method: TAsyncCallArgStringEvent; const Arg: AnsiString): IAsyncCall; overload;
function AsyncCall(Method: TAsyncCallArgWideStringEvent; const Arg: WideString): IAsyncCall; overload;
function AsyncCall(Method: TAsyncCallArgInterfaceEvent; const Arg: IInterface): IAsyncCall; overload;
function AsyncCall(Method: TAsyncCallArgExtendedEvent; const Arg: Extended): IAsyncCall; overload;
function AsyncCallVar(Method: TAsyncCallArgVariantEvent; const Arg: Variant): IAsyncCall; overload;

function AsyncCall(Runnable: IAsyncRunnable): IAsyncCall; overload;

procedure AsyncExec(Method: TNotifyEvent; Arg: TObject; IdleMsgMethod: TAsyncIdleMsgMethod);

{ LocalAsyncCall() executes the given local function/procedure in a separate thread.
  The result value of the asynchronous function is returned by IAsyncCall.Sync() and
  IAsyncCall.ReturnValue().
  The LocalAsyncExec() function calls the IdleMsgMethod while the local procedure is
  executed.

Example:
  procedure MainProc(const S: string);
  var
    Value: Integer;
    a: IAsyncCall;

    function DoSomething: Integer;
    begin
      if S = 'Abc' then
        Value := 1;
      Result := 0;
    end;

  begin
    a := LocalAsyncCall(@DoSomething);
    // do something
    a.Sync;

    LocalAsyncExec(@DoSomething, Application.ProcessMessages);
  end;
}
function LocalAsyncCall(LocalProc: TLocalAsyncProc): IAsyncCall;
function LocalAsyncCallEx(LocalProc: TLocalAsyncProcEx; Param: INT_PTR): IAsyncCall;
procedure LocalAsyncExec(Proc: TLocalAsyncProc; IdleMsgMethod: TAsyncIdleMsgMethod);



{ LocalVclCall() executes the given local function/procedure in the main thread. It
  uses the TThread.Synchronize function which blocks the current thread.
  LocalAsyncVclCall() execute the given local function/procedure in the main thread.
  It does not wait for the main thread to execute the function unless the current
  thread is the main thread. In that case it executes and waits for the specified
  function in the current thread like LocalVclCall().

  The result value of the asynchronous function is returned by IAsyncCall.Sync() and
  IAsyncCall.ReturnValue().

Example:
  procedure TForm1.MainProc;

    procedure DoSomething;

      procedure UpdateProgressBar(Percentage: Integer);
      begin
        ProgressBar.Position := Percentage;
        Sleep(20); // This delay does not affect the time for the 0..100 loop
                   // because UpdateProgressBar is non-blocking.
      end;

      procedure Finished;
      begin
        ShowMessage('Finished');
      end;

    var
      I: Integer;
    begin
      for I := 0 to 100 do
      begin
        // Do some time consuming stuff
        Sleep(30);
        LocalAsyncVclCall(@UpdateProgressBar, I); // non-blocking
      end;
      LocalVclCall(@Finished); // blocking
    end;

  var
    a: IAsyncCall;
  begin
    a := LocalAsyncCall(@DoSomething);
    a.ForceDifferentThread; // Do not execute in the main thread because this will
                            // change LocalAyncVclCall into a blocking LocalVclCall
    // do something
    //a.Sync; The Compiler will call this for us in the Interface._Release method
  end;
}

procedure LocalVclCall(LocalProc: TLocalVclProc; Param: INT_PTR = 0);
function LocalAsyncVclCall(LocalProc: TLocalVclProc; Param: INT_PTR = 0): IAsyncCall;



{ AsyncCallEx() executes the given function/procedure in a separate thread. The
  Arg parameter can be a record type. The fields of the record can be modified
  in the asynchon function.

Example:
  type
    TData = record
      Value: Integer;
    end;

  procedure TestRec(var Data: TData);
  begin
    Data.Value := 70;
  end;

  a := AsyncCallEx(@TestRec, MyData);
  a.Sync; // MyData.Value is now 70
}
function AsyncCallEx(Proc: TAsyncCallArgRecordProc; var Arg{: TRecordType}): IAsyncCall; overload;
function AsyncCallEx(Method: TAsyncCallArgRecordMethod; var Arg{: TRecordType}): IAsyncCall; overload;
function AsyncCallEx(Method: TAsyncCallArgRecordEvent; var Arg{: TRecordType}): IAsyncCall; overload;


{ The following AsyncCall() functions support variable parameters. All reference
  counted types are protected by an AddRef and later Release. The ShortString,
  Extended, Currency and Int64 types are internally copied to a temporary location.

Supported types:
  Integer      :  Arg: Integer
  Boolean      :  Arg: Boolean
  Char         :  Arg: AnsiChar
  WideChar     :  Arg: WideChar
  Int64        :  [const] Arg: Int64
  Extended     :  [const] Arg: Extended
  Currency     :  [const] Arg: Currency
  String       :  [const] Arg: ShortString
  Pointer      :  [const] Arg: Pointer
  PChar        :  [const] Arg: PChar
  Object       :  [const] Arg: TObject
  Class        :  [const] Arg: TClass
  AnsiString   :  [const] Arg: AnsiString
  PWideChar    :  [const] Arg: PWideChar
  WideString   :  [const] Arg: WideString
  Interface    :  [const] Arg: IInterface
  Variant      :  const Arg: Variant

Example:
  procedure Test(const S: string; I: Integer; E: Extended; Obj: TObject); cdecl;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美肥胖老妇做爰| 亚洲另类在线视频| 一二三区精品福利视频| 久久精品99久久久| 色94色欧美sute亚洲线路一久| 日韩三级在线免费观看| 综合电影一区二区三区| 国产精品一色哟哟哟| 欧美日本在线看| 亚洲免费色视频| 成人黄动漫网站免费app| 亚洲精品在线观看网站| 香蕉久久一区二区不卡无毒影院| 99久久精品免费| 久久精品视频一区二区三区| 蜜桃av一区二区三区电影| 欧美亚洲动漫制服丝袜| 亚洲日本在线a| a级精品国产片在线观看| 国产清纯白嫩初高生在线观看91| 久久精品国产网站| 日韩精品中文字幕在线一区| 日本一区中文字幕| 欧美情侣在线播放| 日本91福利区| 日韩免费观看高清完整版在线观看| 香蕉成人啪国产精品视频综合网 | 久久综合狠狠综合久久综合88 | 亚洲一区二区三区精品在线| 91视频你懂的| 亚洲欧美日韩久久| 在线亚洲一区二区| 香蕉加勒比综合久久| 欧美色视频一区| 婷婷成人激情在线网| 7777精品伊人久久久大香线蕉的 | 91福利视频久久久久| 亚洲老司机在线| 欧洲一区二区三区免费视频| 亚洲国产sm捆绑调教视频 | 一区二区三区产品免费精品久久75| 国产精品一色哟哟哟| 国产欧美一区二区精品久导航| 国产.欧美.日韩| 国产精品国产三级国产普通话蜜臀| 成人ar影院免费观看视频| 亚洲人妖av一区二区| 在线视频综合导航| 日日嗨av一区二区三区四区| 日韩视频免费观看高清完整版 | 色哟哟精品一区| 一区二区三区久久| 777a∨成人精品桃花网| 精品一区二区三区免费| 国产精品美女久久久久久久久久久| 成人av在线电影| 亚洲va韩国va欧美va| 日韩欧美国产系列| www.综合网.com| 五月激情综合婷婷| 欧美国产1区2区| 欧美日韩精品是欧美日韩精品| 精品一区中文字幕| 亚洲人成网站色在线观看| 88在线观看91蜜桃国自产| 国产激情精品久久久第一区二区 | 亚洲午夜久久久久久久久电影网 | 亚洲第一电影网| 久久久久久一级片| 欧美性色欧美a在线播放| 国产资源在线一区| 亚洲国产人成综合网站| 国产色一区二区| 在线成人高清不卡| 91免费国产在线观看| 国产综合成人久久大片91| 亚洲一区中文在线| 中文久久乱码一区二区| 91精品国产乱| 日本二三区不卡| 国产盗摄一区二区| 蜜桃精品视频在线| 亚洲国产综合在线| 中文字幕一区视频| 欧美精品一区男女天堂| 欧美日韩精品久久久| 日韩一级黄色片| 99久久精品免费观看| 国内外精品视频| 日本成人中文字幕在线视频| 亚洲激情图片小说视频| 中文字幕 久热精品 视频在线| 91精品国产入口在线| 在线免费一区三区| 91香蕉视频黄| 99久久免费精品高清特色大片| 韩国av一区二区三区在线观看| 三级久久三级久久久| 一区二区高清在线| 亚洲女同一区二区| 日韩一区日韩二区| 国产精品伦理在线| 久久精品亚洲一区二区三区浴池| 欧美xxxxxxxx| 精品久久久久久最新网址| 欧美肥妇毛茸茸| 日韩一区二区三区三四区视频在线观看| 一本久久综合亚洲鲁鲁五月天| 成人午夜精品一区二区三区| 国产综合色在线视频区| 国内精品伊人久久久久av一坑| 美女脱光内衣内裤视频久久网站| 亚洲h在线观看| 亚欧色一区w666天堂| 亚洲第一久久影院| 丝袜亚洲另类欧美| 天天av天天翘天天综合网 | 国产不卡视频一区二区三区| 久久成人免费电影| 狠狠狠色丁香婷婷综合激情| 精品一区二区三区视频| 精品制服美女久久| 国产一区二区福利视频| 成人综合婷婷国产精品久久蜜臀| 国产精品91xxx| 成人国产在线观看| 在线观看欧美日本| 88在线观看91蜜桃国自产| 日韩三级.com| 国产午夜精品一区二区三区视频| 国产欧美精品在线观看| 日韩毛片在线免费观看| 亚洲精品高清视频在线观看| 亚洲精品第1页| 玖玖九九国产精品| 成人毛片在线观看| 一本到不卡免费一区二区| 欧美日韩激情一区二区| 精品伦理精品一区| 国产欧美一区二区精品久导航| 亚洲图片欧美激情| 五月天国产精品| 成人激情免费电影网址| 欧美亚洲尤物久久| 久久―日本道色综合久久| 国产精品福利影院| 日韩激情一二三区| 成人精品视频一区二区三区 | 欧美变态凌虐bdsm| 中文字幕不卡的av| 婷婷综合另类小说色区| 国产黄人亚洲片| 精品视频一区 二区 三区| 久久先锋资源网| 亚洲综合免费观看高清在线观看| 日本不卡一区二区三区| 不卡av免费在线观看| 亚洲一区二区欧美日韩| 九一久久久久久| 91国偷自产一区二区三区成为亚洲经典 | 色香蕉成人二区免费| 日韩久久久精品| 一区二区三区日韩欧美| 九九久久精品视频| 在线观看91精品国产入口| www久久久久| 一区二区三区国产精品| 国产成人免费视| 欧美成人乱码一区二区三区| 亚洲欧美日韩国产综合在线| 激情亚洲综合在线| 欧美视频在线不卡| 亚洲视频网在线直播| 国产一区二区在线看| 欧美日韩日日摸| 亚洲欧美日韩电影| 高潮精品一区videoshd| 日韩欧美一区二区视频| 亚洲国产一区二区三区青草影视| 国产成人日日夜夜| 欧美精品一区二区三区高清aⅴ| 亚洲午夜久久久久久久久电影院| 国产成人免费视频网站高清观看视频| 7777精品伊人久久久大香线蕉完整版| 亚洲人吸女人奶水| 不卡一区在线观看| 国产精品色眯眯| 国产河南妇女毛片精品久久久| 欧美成人综合网站| 免费观看一级欧美片| 在线观看91av| 污片在线观看一区二区| 欧美色图第一页| 亚洲bt欧美bt精品| 欧美日韩精品欧美日韩精品一 | 国产精品网站在线播放| 国产在线国偷精品产拍免费yy| 欧美一三区三区四区免费在线看| 天堂av在线一区| 91精品久久久久久久99蜜桃|