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

📄 fibsafetimer.pas

📁 FIBPlus version 6-96. This is somewhat usefull interbase database components. TFIBDatabase, TFIBTab
💻 PAS
字号:
{***************************************************************}
{ FIBPlus - component library for direct access to Firebird and }
{ InterBase databases                                           }
{                                                               }
{    FIBPlus is based in part on the product                    }
{    Free IB Components, written by Gregory H. Deatz for        }
{    Hoagland, Longo, Moran, Dunst & Doukas Company.            }
{    mailto:gdeatz@hlmdd.com                                    }
{                                                               }
{    Copyright (c) 1998-2009 Devrace Ltd.                       }
{    Written by Serge Buzadzhy (buzz@devrace.com)               }
{                                                               }
{ ------------------------------------------------------------- }
{    FIBPlus home page: http://www.fibplus.com/                 }
{    FIBPlus support  : http://www.devrace.com/support/         }
{ ------------------------------------------------------------- }
{                                                               }
{  Please see the file License.txt for full license information }
{***************************************************************}

unit FIBSafeTimer;

interface

uses
  Windows, SysUtils, Classes;

type
{$I FIBPlus.inc}
  { TFIBCustomTimer }

  TFIBCustomTimer = class(TComponent)
  private
    FActive: Boolean;
    FHandle: Integer;
    FInterval: Integer;
    FOnTimer: TNotifyEvent;
    procedure SetActive(const Value: Boolean);
    procedure SetInterval(const Value: Integer);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
{    procedure Start;
    procedure Stop;}
    property  Enabled: Boolean read FActive write SetActive;
    property  Interval: Integer read FInterval write SetInterval;
    property  OnTimer: TNotifyEvent read FOnTimer write FOnTimer;
  end;

implementation

var
  TimerList: TThreadList;

type
  TSyncThread=class(TThread)
  protected
    FTimer:TFIBCustomTimer;
    procedure Execute; override;
    procedure DoOnTimer;
  end;
  
procedure TimerProc(HWND, uMsg, idEvent, dwTime : Integer); stdcall;
var
  I: Integer;
  Timer: TFIBCustomTimer;
  List:TList;
  st:TSyncThread;
begin
  I := 0;
  List:=TimerList.LockList;
  try
    while I < List.Count do
    begin
      Timer := List.Items[I];
      if (Timer <> nil) and (idEvent = Timer.FHandle) and
         (Assigned(Timer.FOnTimer))
      then
      begin
        if GetCurrentThreadID = MainThreadID then
          Timer.FOnTimer(Timer)
        else
        begin
          st:=TSyncThread.Create(True);
          try
           st.FTimer:=Timer;
           st.Synchronize(st.DoOnTimer);
          finally
           st.Free
          end;
        end ;
        Exit; {恹镱腠

⌨️ 快捷键说明

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