现在我想写一个命令提示窗口中程序在CMD上运行。
不过我要加入TTimer控件。。
目前遇到问题了
我菜我把代码发给大家。。通不过
答对的马上给分
在线等。program testAO;{$APPTYPE CONSOLE}uses
  SysUtils,ExtCtrls;Procedure MyTime(Sender: TObject);
Begin
 // code.
End;var
  aTimer : TTimer;  
begin
  aTimer.Create(nil);
  aTimer.Interval := 60000;
  aTimer.Enabled  := True;
  aTimer.OnTimer := MYtime; 
  // 这里不能指向MYTIME。
  { TODO -oUser -cConsole Main : Insert code here }
end.
最好讲一下原理更好些。

解决方案 »

  1.   

    我找到代码了。
    拿位讲一下原理。program Project1;
    uses
    SysUtils , extctrls;type TMyproc = procedure of object;
    var timer : Ttimer;
    pr: TmyProc;procedure pr;
    begin
    // do smth
    end;
    begin
    timer := ttimer.Create(nil);Timer.OnTimer := pr;
    { TODO -oUser -cConsole Main : Insert code here }
    end.
      

  2.   

    没对通不过。program ChangeFile;{$APPTYPE CONSOLE}uses
      SysUtils,ExtCtrls;type TMyproc = procedure of object;var
      aTimer : TTimer;
      pr: TmyProc;
      
    Procedure pr;
    Begin
     // code.
    End;
    begin
      aTimer.Create(nil);
      aTimer.Interval := 60000;
      aTimer.Enabled  := True;
      aTimer.OnTimer := pr; 
      { TODO -oUser -cConsole Main : Insert code here }
    end.
      

  3.   

    这个也不用讲了,看了李维老师的<inside in VCL>前几章就明白了
      

  4.   

    用API最好了。SetTimer
    我写的一个小程序,用到了SetTimer定时,你看看吧:
    ///我能做的只是通过一外部程序来屏蔽广告:
    {--- 功能:---}
    //1.屏蔽广告。
    //2.屏蔽Flash动画,以及浮动在页面里的Flash动画。
    {--- 原理:---}
    //1.广告窗口的WorkerW类和Shell DocObject View类的rect.top的值是相同的;
    //2.正常IE窗口的WorkerW类和Shell DocObject View类的rect.top的值是不相同的;
    {--- 运行环境: ---}
    //1.Delphi7.0 + WinXP。
    //2.采用VC自带的SPY++查看窗口类名。
    //////////////////////////// 2004-9-10 by hottey  //////////////////////////////
    program Kill;uses
      Windows;const
      WM_CLOSE = $0010;var
      {--- 定时器ID ---}
      iTimerID: integer;
      MSg: TMsg;
      {--- 初始为0,表明从第一个窗口开始查找 ---}
      Next: HWND = 0;////定时器回调函数
    function Killer(hWd: HWND; umsg: UINT; iTimerID: UINT; dwTime: DWORD):LRESULT;
    var
      reca, recb: TRect;
      IehWnd, WorkerW, View, Flash: HWND;
    begin
      Result := 0;
      {--- 寻找类名为'IEFrame'的IE窗口,从Next=0开始查找 ---}
      IehWnd := FindWindowEx(0, Next, 'IEFrame', nil);
      if IehWnd <> 0 then
      begin
        WorkerW:= FindWindowEx(IehWnd, 0, 'WorkerW', nil);
        View:= FindWindowEx(IehWnd, 0, 'Shell DocObject View', nil);
        {--- Flash为网页上Flash动画的句柄 ---}
        Flash := FindWindowEx(GetWindow(View, GW_CHILD), 0, 'MacromediaFlashPlayerActiveX', nil);
        if Flash <> 0 then
        {--- 关闭网页上所有的Flash动画---}
          PostMessage(Flash, WM_CLOSE, 0, 0);
        {--- 判断WorkerW和Shell DocObject View的rect.top的值,相等则表明此IE窗口为广告窗口 ---}
        Windows.GetWindowRect(WorkerW, reca);
        Windows.GetWindowRect(View, recb);
        if (reca.Top = recb.Top) then
        {--- 关闭广告窗口 ---}
            PostMessage(IehWnd, WM_CLOSE, 0, 0)
        else
        {--- IehWnd不是广告窗口,则从IehWnd这个窗口后继续查找(Next := IehWnd) ---}
          Next := IehWnd;
      end else
        {--- 桌面上若无IE窗口则将Next清0,方便下次查找 ---}
        Next := 0;
    end;///程序开始
    begin
      {--- 设置定时器,Killer是它的回调函数 ---}
      iTimerID := SetTimer(0, 0, 100, @Killer);
      MessageBox(0,'广告杀手已经启动','提示:',0);
      {--- 消息循环 ---}
      while GetMessage(Msg, 0, 0, 0) do
      begin
        TranslateMessage(Msg);
        DispatchMessage(Msg);
      end;
    end.///程序最后应该杀死定时器  KillTimer(0, iTimerID); 
    ///本例中没有这样做:-P
    ///问:本来我用SPY++查看时广告窗口和正常IE窗口的IEFrame类(即主窗口)的
    ///Client Rect的Left 和 Top值应该不一样的,广告{3,29}-IE{4,30}但用
    ///GetClientRect();函数得到的却是广告{0,0}-IE{0,0}...无奈啊…………
      

  5.   

    用API函数SetTimer:
    给你一个我写的程序,里面用到了SetTimer
    ///我能做的只是通过一外部程序来屏蔽广告:
    {--- 功能:---}
    //1.屏蔽广告。
    //2.屏蔽Flash动画,以及浮动在页面里的Flash动画。
    {--- 原理:---}
    //1.广告窗口的WorkerW类和Shell DocObject View类的rect.top的值是相同的;
    //2.正常IE窗口的WorkerW类和Shell DocObject View类的rect.top的值是不相同的;
    {--- 运行环境: ---}
    //1.Delphi7.0 + WinXP。
    //2.采用VC自带的SPY++查看窗口类名。
    //////////////////////////// 2004-9-10 by hottey  //////////////////////////////
    program Kill;uses
      Windows;const
      WM_CLOSE = $0010;var
      {--- 定时器ID ---}
      iTimerID: integer;
      MSg: TMsg;
      {--- 初始为0,表明从第一个窗口开始查找 ---}
      Next: HWND = 0;////定时器回调函数
    function Killer(hWd: HWND; umsg: UINT; iTimerID: UINT; dwTime: DWORD):LRESULT;
    var
      reca, recb: TRect;
      IehWnd, WorkerW, View, Flash: HWND;
    begin
      Result := 0;
      {--- 寻找类名为'IEFrame'的IE窗口,从Next=0开始查找 ---}
      IehWnd := FindWindowEx(0, Next, 'IEFrame', nil);
      if IehWnd <> 0 then
      begin
        WorkerW:= FindWindowEx(IehWnd, 0, 'WorkerW', nil);
        View:= FindWindowEx(IehWnd, 0, 'Shell DocObject View', nil);
        {--- Flash为网页上Flash动画的句柄 ---}
        Flash := FindWindowEx(GetWindow(View, GW_CHILD), 0, 'MacromediaFlashPlayerActiveX', nil);
        if Flash <> 0 then
        {--- 关闭网页上所有的Flash动画---}
          PostMessage(Flash, WM_CLOSE, 0, 0);
        {--- 判断WorkerW和Shell DocObject View的rect.top的值,相等则表明此IE窗口为广告窗口 ---}
        Windows.GetWindowRect(WorkerW, reca);
        Windows.GetWindowRect(View, recb);
        if (reca.Top = recb.Top) then
        {--- 关闭广告窗口 ---}
            PostMessage(IehWnd, WM_CLOSE, 0, 0)
        else
        {--- IehWnd不是广告窗口,则从IehWnd这个窗口后继续查找(Next := IehWnd) ---}
          Next := IehWnd;
      end else
        {--- 桌面上若无IE窗口则将Next清0,方便下次查找 ---}
        Next := 0;
    end;///程序开始
    begin
      {--- 设置定时器,Killer是它的回调函数 ---}
      iTimerID := SetTimer(0, 0, 100, @Killer);
      MessageBox(0,'广告杀手已经启动','提示:',0);
      {--- 消息循环 ---}
      while GetMessage(Msg, 0, 0, 0) do
      begin
        TranslateMessage(Msg);
        DispatchMessage(Msg);
      end;
    end.///程序最后应该杀死定时器  KillTimer(0, iTimerID); 
    ///本例中没有这样做:-P
    ///问:本来我用SPY++查看时广告窗口和正常IE窗口的IEFrame类(即主窗口)的
    ///Client Rect的Left 和 Top值应该不一样的,广告{3,29}-IE{4,30}但用
    ///GetClientRect();函数得到的却是广告{0,0}-IE{0,0}...无奈啊…………
      

  6.   

    同意 ysai(蓝色忧郁) 的说法
    楼主将 pr定义为普通过程就可以了