TConsoleApp
http://forum.lazarus.freepascal.org/index.php?topic=33937.0
- program consoleapp;
- {$mode objfpc}{$H+}
- uses
- {$IFDEF UNIX}{$IFDEF UseCThreads}
- cthreads,
- {$ENDIF}{$ENDIF}
- Classes, SysUtils, CustApp
- { you can add units after this },
- fpTimer;
- type
- { TConsoleApp }
- TConsoleApp = class(TCustomApplication)
- protected
- procedure DoRun; override;
- public
- Timer1: TFPTimer;
- constructor Create(TheOwner: TComponent); override;
- destructor Destroy; override;
- procedure Timer1Exec( Sender : TObject );
- end;
- { TConsoleApp }
- procedure TConsoleApp.Timer1Exec( Sender : TObject );
- begin
- writeln('timer write');
- end;
- procedure TConsoleApp.DoRun;
- begin
- while true do
- begin
- writeln(datetimetostr(now));
- sleep(1000);
- timer1.StartTimer;
- end;
- Terminate;
- end;
- constructor TConsoleApp.Create(TheOwner: TComponent);
- begin
- inherited Create(TheOwner);
- StopOnException:=True;
- end;
- destructor TConsoleApp.Destroy;
- begin
- inherited Destroy;
- end;
- var
- Application: TConsoleApp;
- begin
- Application:=TConsoleApp.Create(nil);
- Application.Title:='ConsoleApp';
- Application.Timer1 := TFPTimer.Create(nil);
- Application.Timer1.interval := 3000;
- Application.Timer1.onTimer := @Application.Timer1Exec;
- Application.Run;
- Application.Free;
- end.
评论