TConsoleApp

http://forum.lazarus.freepascal.org/index.php?topic=33937.0


  1. program consoleapp;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes, SysUtils, CustApp
  10.   { you can add units after this },
  11.   fpTimer;
  12.  
  13. type
  14.  
  15.   { TConsoleApp }
  16.  
  17.   TConsoleApp = class(TCustomApplication)
  18.   protected
  19.     procedure DoRun; override;
  20.   public
  21.     Timer1: TFPTimer;
  22.     constructor Create(TheOwner: TComponent); override;
  23.     destructor Destroy; override;
  24.     procedure Timer1Exec( Sender : TObject );
  25.   end;
  26.  
  27. { TConsoleApp }
  28.  
  29. procedure TConsoleApp.Timer1Exec( Sender : TObject );
  30. begin
  31.   writeln('timer write');
  32. end;
  33.  
  34. procedure TConsoleApp.DoRun;
  35. begin
  36.   while true do
  37.   begin
  38.     writeln(datetimetostr(now));
  39.     sleep(1000);
  40.     timer1.StartTimer;
  41.   end;
  42.   Terminate;
  43. end;
  44.  
  45. constructor TConsoleApp.Create(TheOwner: TComponent);
  46. begin
  47.   inherited Create(TheOwner);
  48.   StopOnException:=True;
  49. end;
  50.  
  51. destructor TConsoleApp.Destroy;
  52. begin
  53.   inherited Destroy;
  54. end;
  55.  
  56. var
  57.   Application: TConsoleApp;
  58. begin
  59.   Application:=TConsoleApp.Create(nil);
  60.   Application.Title:='ConsoleApp';
  61.   Application.Timer1 := TFPTimer.Create(nil);
  62.   Application.Timer1.interval := 3000;
  63.   Application.Timer1.onTimer := @Application.Timer1Exec;
  64.   Application.Run;
  65.   Application.Free;
  66. end.
  67.  

评论

此博客中的热门博文

JavaScript quiz - Scoping related

Java SMTP

qtCreator + Eclipse