3.我想定时读取数据库怎么没反应哪?
你看:
unit Unit1;
interface
uses
; Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
; Db, DBTables, ExtCtrls;
type
; TService2 = class(TService)
; ; Timer1: TTimer;
; ; Query1: TQuery;
; ; Database1: TDatabase;
; ; procedure Timer1Timer(Sender: TObject);
; private
; ; { Private declarations }
; public
; ; function ChangFile:string;
; ; function GetServiceController: TServiceController; override;
; ; procedure GetData;
; ; { Public declarations }
; end;
var
; Service2: TService2;
implementation
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
; Service2.Controller(CtrlCode);
end;
function TService2.ChangFile: string;
begin
begin
; Query1.DatabaseName := 'xxxx';
; ; with Query1 do
; ; ;begin
; ; ;Close;
; ; ;SQL.Clear;
; ; ;SQL.Add('select xx字段 From 表名 order by xx字段 DESC');
; ; ;ExecSQL;
; ; ;Active:=true;
; ; ;first;
; ; ;result:=Query1.FIELDS[0].ASSTRING;
; ; ; end;
end;
end;
procedure TService2.GetData;
var str:string;
; MyTxtFile:textFile;
; i:integer;
begin
; str:=ChangFile;
; Assignfile(MyTxtFile,'E:/My Documents/Service相关/bb.txt');
; Rewrite(MyTxtFile);
; try
; ;for ; ;i:=1 to 5 do
; ;writeln(MytxtFile,str);
; ;finally
; ;CloseFile(MyTxtFile);
; end;
end;
function TService2.GetServiceController: TServiceController;
begin
; Result := ServiceController;
end;
procedure TService2.Timer1Timer(Sender: TObject);
begin
Timer1.Interval:=10000;
GetData;
Timer1.Enabled:=true;
end;
end.
只是在安装服务时,运行了一下,然后再无反应。