当 它的Enabled为真的话,他是属于开一个线程来执行它里面的代码吗?当它执行它里面的代码的同时我的程序能否执行其它代码(不在这个控件里面的代码,比如代码在按钮的单击触发事件)?当它调用某个函数的同时,我能否调用它调用的那个函数

解决方案 »

  1.   

    timer要是能当线程用,那还在用复杂的线程写程序的人就都可以去死了
      

  2.   


    timer不是线程,他不过就是一个组件而已,继承自TComponent,你可以试试在其事件中写一个死循环,看看还能做其它事情吗
      

  3.   

    哦,谢谢你们了,请问怎么用代码表达一个类似timer的控件?
    不想用循环语句,循环语句太耗CPU了
      

  4.   

    下贴中6楼(把里面的TManagedObject改为TObject就可以)http://topic.csdn.net/u/20080731/15/e3b3d0af-2fe1-40a7-8c52-521e96d50a34.html
      

  5.   

    UnitManagedObject单元呢?僵兄呀~
      

  6.   

    21楼http://topic.csdn.net/u/20081126/17/2dfc3e40-a899-4a76-8159-483bff1217a2.html
      

  7.   

    if pTimer.Attach <> pTimer then //这里错误了,
    错误消息,
    [Error] U_Timer.pas(51): Undeclared identifier: 'Attach'
    [Error] U_Timer.pas(84): Undeclared identifier: 'DWORD_PTR'
    [Fatal Error] Unit1.pas(8): Could not compile used unit 'U_Timer.pas'
    怎么办?(*^__^*) 嘻嘻……。能否给分完整的,僵兄?
      

  8.   

    TManagedObject我已经在9楼给你链接了.type
      DWORD_PTR = LONGWORD;
      

  9.   

    TTimer调用的是Windows API里的几个Timer相关的函数。
    响应Windows的Timer相关的消息。
      

  10.   

    var
      pTimer: TPreciseTimer;
    僵兄给的PreciseTimerUnit里面的TPreciseTimer类都没定义过Attach都没有定义。
    所以报这个错误[Error] U_Timer.pas(51): Undeclared identifier: 'Attach' 。procedure PurifierTimerProc(uTimerID, uMessage: UINT;
        dwUser, dw1, dw2: DWORD) stdcall;
    var
      pTimer: TPreciseTimer;
    begin  pTimer := TPreciseTimer(dwUser);
      if pTimer.Attach <> pTimer then  //这里报错了,请问改怎么定义呢?这个过程在PreciseTimerUnit单元的
        Exit;
      try
        pTimer.RaiseTimerEvent;
      finally
        pTimer.Free;
      end;
    end;
      

  11.   

    就是调用了API SetTimer KillTimer
      

  12.   

    僵哥 TManagedObject 类还没公布,呵呵
      

  13.   

    还可以把Timer放到线程当中,参考下贴3楼http://topic.csdn.net/u/20081218/15/28716f7e-d780-4384-a148-c354d85866ce.html