⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unaclasses.pas

📁 Voice Commnucation Components for Delphi
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    function locate(value: unsigned): int; overload;
    function locate(value: int): int; overload;
    {DP:METHOD
      Creates a array and copies list items into it.
      <BR />If includeZeroIndexCount is true, the first elemet of array will contain number of items in it.
      <P />Returns size of created array (in bytes).
    }
    function copyTo(out list: pInt32Array; includeZeroIndexCount: bool): int;
    {DP:METHOD
      Returns number of items processed.
      If listSize is -1 list has "zero index count", i.e. number of items is stored as first item of the list.
    }
    function copyFrom(list: pInt32Array; listSize: int = -1; copyOperation: unaListCopyOpEnum = unaco_add; startIndex: unsigned = 0): int; overload;
    function copyFrom(list: unaList; copyOperation: unaListCopyOpEnum = unaco_add; startIndex: unsigned = 0): int; overload;
    {DP:METHOD
      Returns number of items copied.
    }
    function assign(list: unaList): int;
    {DP:METHOD
    }
    function waitForData(timeout: unsigned = 100): bool;
    {DP:METHOD
    }
    function checkDataEvent(): bool;
    //
    {DP:METHOD
      Number of items in the list.
    }
    property count: unsigned read f_count;
    {DP:METHOD
      Set this property to true for lists which know how to free own items, to allow items to be freed by the list.
    }
    property autoFree: bool read f_autoFree write f_autoFree;
    {}
    property timeOut: unsigned read f_timeout write f_timeout default 1000;
    {DP:METHOD
      Returns list item by it index.
    }
    property item[index: unsigned]: pointer read get write doSetItem; default;
  {$IFDEF DEBUG}
    property debugTitle: string read f_debugTitle;
  {$ENDIF}
    {DP:METHOD
      When this property is true list will not use gate to protect internal data in multi-threading access. This may increase performance a little.
    }
    property oneThreadUser: bool read f_oneThreadUser write f_oneThreadUser;
    //
    {DP:METHOD
      Fires when list item is needed to be released. NOTE: item[index] could be nil.
    }
    property onItemRelease: unaListOnItemReleaseEvent read f_onItemRelease write f_onItemRelease;
    {DP:METHOD
      Fires when list item is about to be removed from the list.
    }
    property onItemBeforeRemove: unaListOnItemBeforeRemoveEvent read f_onItemBeforeRemove write f_onItemBeforeRemove;
    {DP:METHOD
      Specifies whether list contains Delphi objects,
      which should be freed (if autoFree is true) upon removal.
    }
    property isObjects: bool read f_isObjects write f_isObjects;
    {DP:METHOD
      Returns true if list was locked by someone (even same thread).
      Could be used only for checking, like the following: "if (not list.isLocked and list.lock()) then ..."
    }
    function isLocked(): bool;
    {DP:METHOD
      Returns true if there are no items in the list.
      Note, that due to multi-threading issues returned result may be not accurate.
      Use for quick checks only, like status update.
    }
    function isEmpty(): bool;
  end;


  //
  // -- unaRecordList --
  //
  {DP:CLASS
    List of records (pointers).
    <P />In this list memory pointed by items can be freed automatically (depending on autoFree property value).
  }
  unaRecordList = class(unaList)
  protected
    procedure releaseItem(index: unsigned; doFree: unsigned); override;
  public
    constructor create(autoFree: bool = true{$IFDEF DEBUG}; const title: string = ''{$ENDIF});
  end;


  //
  // -- unaIdList --
  //

  {DP:METHOD
    This list is usefull when you wish to access items by their IDs rather than by indexes.
    <BR />It uses internal array to store the ID of every item, so item could be located much faster.
  }
  unaIdList = class(unaList)
  private
    f_allowDI: bool;
    f_idList64: pInt64Array;
    f_idList64Capacity: uint;
    //
    procedure setIdListCapacity(value: uint);
  protected
    procedure doSetCapacity(value: unsigned); override;
    procedure notifyBeforeRemove(index: unsigned); override;
    {DP:METHOD
      Override this method to provide some implementation of returning the ID of the item.
    }
    function getId(item: pointer): int64; virtual;
    //
    function add2(item: pointer): unsigned; override;
    function insert2(index: unsigned; item: pointer): int; override;
    procedure setItem2(index: unsigned; item: pointer; doFree: unsigned = 2); override;
    //
    procedure doReverse(); override;
    function doCopyFrom(list: pInt32Array; listSize: int = -1; copyOperation: unaListCopyOpEnum = unaco_add; startIndex: unsigned = 0): int; override;
  public
    procedure AfterConstruction(); override;
    procedure BeforeDestruction(); override;
    //
    {DP:METHOD
      Returns first item with given ID.
    }
    function itemById(id: int64; startingIndex: unsigned = 0; timeout: unsigned = INFINITE): pointer;
    {DP:METHOD
      Returns index of first item with given ID.
    }
    function locateById(id: int64; startingIndex: unsigned = 0): int;
    {DP:METHOD
      Removes item with specified ID.
    }
    function removeById(id: int64; doFree: uint = 2): bool;
    {DP:METHOD
      Assigns new Ids for each item in the list. Returns number of items updated.
    }
    function updateIds(): unsigned;
    //
    property allowDuplicateId: bool read f_allowDI write f_allowDI;
  end;


  //
  // -- unaList64 --
  //
  {DP:CLASS
    List of int64 values.
    <P />In this list memory pointed by items will be freed automatically (depending on autoFree property value).
  }
  unaList64 = class(unaRecordList)
  protected
  public
    function add(item: int64): unsigned;
    function insert(index: unsigned; item: int64): unsigned;
    function removeItem(item: int64): bool;
    function get(index: unsigned): int64;
    procedure setItem(index: unsigned; item: int64);
    function locate(value: int64): int;
    //
    property item[index: unsigned]: int64 read get write setItem;
  end;


  //
  // -- unaObjectList --
  //

  {DP:CLASS
    List of objects.
    <P />autoFree = true indicates that items will be freed automatically.
  }
  unaObjectList = class(unaList)
  protected
  public
    constructor create(autoFree: bool = true{$IFDEF DEBUG}; const title: string = ''{$ENDIF});
  end;


  //
  // -- unaRecordList --
  //
  {DP:CLASS
    List of objects implementing interfaces. Takes care of default ref counting.
    <P />autoFree = true indicates that items will be released automatically.
  }
  unaIntfObjectList = class(unaList)
  protected
    procedure releaseItem(index: unsigned; doFree: unsigned); override;
    function add2(item: pointer): unsigned; override;
  public
    constructor create(autoFree: bool = true{$IFDEF DEBUG}; const title: string = ''{$ENDIF});
    //
    {DP:METHOD
      Adds one ref to interfaced object stroed in the list. Returns resulting refcount of an item.
    }
    function itemAddRef(index: unsigned): int;
  end;


  //
  // -- unaStringList --
  //

  {DP:CLASS
    List of strings.
  }
  unaStringList = class(unaRecordList)
  private
    //
    function allocateBuf(const item: string): pointer;
    function getText(): string;
    procedure setText(const value: string);
    function getValue(const index: string): string;
    procedure setValue(const index, value: string);
    function getName(const index: int): string;
    procedure setName(const index: int; const value: string);
  protected
    //
  public
    {DP:METHOD
      Adds new string into list.
    }
    function add(const value: string): unsigned;
    {DP:METHOD
      Returns a string by its index.
    }
    function get(index: unsigned): string;
    //
    function insert(index: unsigned; const value: string): unsigned;
    {DP:METHOD
      Performs a case sensitive (if exact is true) or not (if exact is false) search.
      Returns string index or -1 if specified string was not found.
    }
    function locate(const value: string; exact: bool = true): int;
    //
    function locateValue(const name: string): int;
    {DP:METHOD
      Changes an item with specifiled index in the list.
    }
    procedure setItem(index: unsigned; const item: string);
    {DP:METHOD
      Replaces content of text with data read from a file.
    }
    function readFromFile(const fileName: wideString): int;
    //
    property text: string read getText write setText;
    //
    property names[const index: int]: string read getName write setName;
    property values[const index: string]: string read getValue write setValue;
  end;


  //
  // -- unaWideStringList --
  //

  {DP:CLASS
    List of wide strings.
  }
  unaWideStringList = class(unaRecordList)
  private
    //
    function allocateBuf(const item: wideString): pointer;
    function getText(): wideString;
    procedure setText(const value: wideString);
    function getValue(const index: wideString): wideString;
    procedure setValue(const index, value: wideString);
  protected
    //
  public
    {DP:METHOD
      Adds new string into list.
    }
    function add(const value: wideString): unsigned;
    {DP:METHOD
      Returns a string by its index.
    }
    function get(index: unsigned): wideString;
    {DP:METHOD
      Performs a case sensitive (if exact is true) or not (if exact is false) search.
      Returns string index or -1 if specified string was not found.
    }
    function locate(const value: wideString; exact: bool = true): int;
    //
    function locateValue(const name: wideString): int;
    {DP:METHOD
      Changes an item with specifiled index in the list.
    }
    procedure setItem(index: unsigned; const item: wideString);
    {DP:METHOD
      Replaces content of text with data read from a file.
    }
    function readFromFile(const fileName: wideString): int;
    //
    property text: wideString read getText write setText;
    //
    property values[const index: wideString]: wideString read getValue write setValue;
  end;


  //
  // -- unaStringList --
  //

  {DP:CLASS
    List of file names.
  }
  unaFileList = class(unaRecordList)
  private
    f_root: wideString;
    f_mask: wideString;
    f_includeSubF: bool;
    //
    f_path: unaStringList;
    f_subPath: unaStringList;
    f_curDir: wideString;
    //
    procedure addRecord(data: WIN32_FIND_DATAW); overload;
    procedure addRecord(data: WIN32_FIND_DATAA); overload;
  public
    constructor create(const path, mask: wideString; includeSubF: bool = false);
    //
    procedure AfterConstruction(); override;
    procedure BeforeDestruction(); override;
    //
    function refresh(const path, mask: wideString; includeSubF: bool = false; clearUp: bool = true; subLevel: int = 0): bool;
    //
    function getFileName(index: int): wideString;
    function getFileDate(index: int; dateIndex: int): SYSTEMTIME;
    function getFileSize(index: int): int64;
    function getSubLevel(index: int): uint;
    function getAttributes(index: int): uint;
    function getPath(index: int): wideString;
    function getSubPath(index: int): wideString;
    //
    property root: wideString read f_root;
    property mask: wideString read f_mask;
  end;


  //
  // -- unaObjectList --
  //

  {DP:CLASS
    Registry access class.
  }
  unaRegistry = class(unaObject)
  private
    f_root: HKEY;
    f_key: HKEY;
  public
    constructor create(root: HKEY = HKEY_CURRENT_USER);
    procedure BeforeDestruction(); override;
    //
    function open(const keyPath: wideString; access: unsigned = KEY_READ): int;
    procedure close();
    function loadKeyNames(list: unaStringList): int;
    //
    {DP:METHOD
      Returns item value stored in Windows registry.
    }
    function get(const name: wideString; var buf: pointer): unsigned; overload;
    function get(const name: wideString; buf: pointer; size: unsigned): unsigned; overload;
    function get(const name: wideString; def: int): int; overload;
    function get(const name: wideString; def: unsigned): unsigned; overload;
    function get(const name: wideString; const def: string): string; overload;
    {$IFDEF __AFTER_D5__ }
    function get(const name: wideString; const def: wideString): wideString; overload;
    {$ENDIF }
    function get(const name: wideString; const def: int64): int64; overload;
    {DP:METHOD
      Sets the value of item in Windows registry.
    }
    function setValue(const name: wideString; buf: pointer; size: unsigned; keyType: int): int; overload;
    function setValue(const name: wideString; value: int): bool; overload;
    function setValue(const name: wideString; value: unsigned): bool; overload;
    function setValue(const name: wideString; const value: string): bool; overload;
    function setValue(const name: wideString; const value: wideString): bool; overload;
    function setValue(const name: wideString; const value: int64): bool; overload;
  end;

const
  c_max_threads	=	1024;	// max number of threads	


type
  //
  // -- unaThread --
  //

  unaThread = class;
  {DP:METHOD
    Event used for thread execution.
  }
  unaThreadOnExecuteMethod = function(thread: unaThread): int of object;

  unaThreadManager = class;
  unaThreadStatus = (unatsStopped, unatsStopping, unatsPaused, unatsRunning, unatsBeforeRunning);


  {DP:CLASS
    This is wrapper class over the Windows threads.
    Refer to MSDN documentation for more information about Windows threads.
  }
  unaThread = class(unaObject)
  private
    f_globalThreadIndex: unsigned;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -