谢谢lich,!
源码如下:
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Buttons, Grids, DBGrids, ExtCtrls,
IAgaloLED,IdUDPServer, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPClient, Sockets, IdAntiFreezeBase, IdAntiFreeze,
IdStack, IdSocketHandle, ImgList, RzAnimtr;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
DBGrid1: TDBGrid;
Button1: TButton;
DBGrid2: TDBGrid;
Button2: TButton;
DataSource1: TDataSource;
DataSource2: TDataSource;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
ADOConnection2: TADOConnection;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
tquerythread= class(tthread)
private
FADOConnection:TADOConnection;
FADOQuery:TADOQuery;
fdatasource:tdatasource;
fqueryexception:exception;
procedure connectdatasource;
procedure showqryerror;
protected
procedure execute;override;
public
constructor create(adoconnection:tadoconnection;adoquery:tadoquery;datasource:tdatasource);virtual;
end;
var
Form1: TForm1;
implementation
constructor tquerythread.create(adoconnection:tadoconnection;adoquery:tadoquery;datasource:tdatasource);
begin
inherited create(true);
fadoquery:=adoquery;
fdatasource:=datasource;
freeonterminate:=true;
resume;
end;
procedure tquerythread.execute;
begin
try
fadoquery.Open;
synchronize(connectdatasource);
except
end;
end;
procedure tquerythread.connectdatasource;
begin
fdatasource.dataset:=fadoquery;
end;
procedure tquerythread.showqryerror;
begin
application.ShowException(fqueryexception);
end;
procedure runbackgroundquery(adoconnection:tadoconnection;adoquery:tadoquery;datasource:tdatasource);
begin
tquerythread.create(adoconnection,adoquery,datasource);
end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var hthread:thandle;
threadid:word;
d,dd:tdatetime;
easid:string;
begin
d:=strtodatetime('2003-10-17 0:00:00');
dd:=strtodatetime('2003-10-17 23:59:59');
easid:='100-1-2';
with adoquery1do
begin
close;
sql.Clear;
sql.Add('select count(*) from alarm_info where alarm_time>=:d and alarm_time<=:dd');
//
parameters[0].Value:=d;
parameters[1].Value:=dd;
end;
runbackgroundquery(adoconnection1,adoquery1,datasource1);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
with adoquery2do
begin
close;
sql.Clear;
sql.Add('select * from t');
open;
end;
end;
end.
var
Form1: TForm1;
ss:integer;
implementation
constructor tquerythread.create(adoconnection:tadoconnection;adoquery:tadoquery;datasource:tdatasource);
begin
inherited create(true);
fadoquery:=adoquery;
fdatasource:=datasource;
freeonterminate:=true;
resume;
end;
procedure tquerythread.execute;
begin
try
fadoquery.Open;
synchronize(connectdatasource);
except
end;
end;
procedure tquerythread.connectdatasource;
begin
fdatasource.dataset:=fadoquery;
end;
procedure tquerythread.showqryerror;
begin
application.ShowException(fqueryexception);
end;
procedure runbackgroundquery(adoconnection:tadoconnection;adoquery:tadoquery;datasource:tdatasource);
begin
tquerythread.create(adoconnection,adoquery,datasource);
end;
//function querythread(p
ointer):longint;stdcall;
//begin
//runbackgroundquery(adoconnection1,adoquery1,datasource1);
//end;
//
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var hthread:thandle;
threadid:word;
d,dd:tdatetime;
easid:string;
begin
d:=strtodatetime('2003-10-17 0:00:00');
dd:=strtodatetime('2003-10-17 23:59:59');
easid:='100-1-2';
with adoquery1do
begin
close;
sql.Clear;
sql.Add('select count(*) from alarm_info where alarm_time>=:d and alarm_time<=:dd');
//
parameters[0].Value:=d;
parameters[1].Value:=dd;
end;
runbackgroundquery(adoconnection1,adoquery1,datasource1);
{ with adoquery2do
begin
close;
sql.Clear;
sql.Add('select rno,eas_id,eas_name,eas_ip,alarm_time from alarm_info where alarm_time>=:d and alarm_time<=:dd');
parameters[0].Value:=d;
parameters[1].Value:=dd;
end;
runbackgroundquery(adoconnection2,adoquery2,datasource2);
}
end;
procedure TForm1.Button2Click(Sender: TObject);
var
I: Integer;
s:string;
begin
for I := 0 to 1000000do
// Iterate
begin
s:=inttostr(i);
end;
// for
edit1.Text:=s;
end;
// runbackgroundquery(adoconnection2,adoquery2,datasource2);
//end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if l.LedOn=true then
l.LedOn:=false
else
l.LedOn:=true;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
d,dd:tdatetime;
begin
d:=strtodatetime('2003-10-17 0:00:00');
dd:=strtodatetime('2003-10-17 23:59:59');
with adoquery3do
begin
close;
sql.Clear;
sql.Add('select * from alarm_info where alarm_time>=:d');
parameters[0].Value:=d;
open;
end;
end;
procedure TForm1.UDPServerUDPRead(Sender: TObject;
AData: TStream;
ABinding: TIdSocketHandle);
var
s:string;
i,sum:integer;
op:tlocateoptions;
begin
l.LedOn:=true;
adocommand1.CommandText:='insert into t(a) values
s)';
adocommand1.Parameters[0].Value:=s;
adocommand1.Execute;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
begin
if l.LedOn=true then
//颜色不为本身默认值和报警后的值时
begin
ss:=ss+1;
if (ss<2) then
beep()
else
begin
l.LedOn:=false;
ss:=0;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
UDPSERVER.Binding.IP:='192.168.0.210';
UDPSERVER.Binding.Port:=9901;
UDPSERVER.Active:=TRUE;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
adoquery1.Close;
adoquery2.Close;
end;
procedure TForm1.Button5Click(Sender: TObject);
var
d,dd:tdatetime;
begin
d:=strtodatetime('2003-10-17 0:00:00');
dd:=strtodatetime('2003-10-17 23:59:59');
with adoquery4do
begin
close;
sql.Clear;
sql.Add('select * from t');
// sum(cx) as c
open;
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
var
s:string;
op:tlocateoptions;
i,sum:integer;
begin
{adocommand1.CommandText:='insert into t(a) values
s)';
adocommand1.Parameters[0].Value:=s;
adocommand1.Execute;
}
adoquery4.Open;
//adotable1.Locate('a','333',op);
end;
end.