PROGRAM Project1;
Uses? svcmgr ,? service in 'service.pas' {Netor1: TSERVICE} ,? thread in 'thread.pas';
{$ R * .res}
Begin? Application.initialize ;? Application.createform (TNETOR1, NETOR1) ;? Application.Run; End.
?
Unit service;
Interface
Uses? Windows, Messages, Sysutils, Classes, Graphics, Controls, SVCMGR, Dialogs
? Type Tnetor1 = class (TService) ??? procedure ServiceStart (Sender: TService; var Started: Boolean); ??? procedure ServiceStop (Sender: TService; var Stopped: Boolean) ;? private ??? {Private declarations}? PUBLIC ??? Function GetServiceController: TSERVICECONTROLLLER; OVERRIDE; ??? {public declarations}?
Var? Netor1: Tsetor1;
ImplementationUses thread;
{$ R * .dfm}
Procedure ServiceController (Ctrlcode: DWORD); stdcall; begin? Netor1.controller (ctrlcode);
Function TNETOR1.GETSERVICECONTROLLLER: TSERVICECONTROLLLER; begin? result: = serviceController;
Procedure TNetor1.ServiceStart (Sender: TService; Var Started: Boolean); Var THRE: Threa; BeginThre: = Threa.create (false); started: = true;
Procedure TNetor1.ServiceStop (Sender: TService; Var Stopped: Boolean); beginthre.terminate; stopped: = true;
END;
End.
?
UNIT THREAD;
Interface
Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Dialogs;
TYPE? THREA = Class (TTHREAD)? PRIVATE ??? {private declarations}? protected ??? procedure execute; override ;?
IMPLEMENTATION
{Important: Methods and Properties Of Objects in Visual Components CAN Only Be? Used in a Method Called Using Synchronize, for Example,
????? synchronize (UpdateCaption);
? And UpdateCaption Could Look Like,
??? procedure thread.updatecaption; ??? begin ????? form1.caption: = 'updated in a thread'; ??? end;} {thread}
ProCedure; Var logfile: TextFile; var logtxt: tfilestream; beginwhile true do beg? if not fileexists ('c: /log.txt') Then ?? begin ?? logtxt: = TFileStream.create ('C: / Log.txt ', fmcreate; ?? logtxt.free ;? End ;? assignfile (logfile,' c: /log.txt ');? append (logfile) ;? Writeln (logfile, datetimetostr (now));? Closefile (logfile) ;? Sleep (5000); end; end;
End.