unit Unit3;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DBCtrls, Grids, DBGrids, StdCtrls, DB, ADODB, DBTables;type
TForm3 = class(TForm)
Button1: TButton;
Session1: TSession;
Database1: TDatabase;
Table1: TTable;
Memo1: TMemo;
Label1: TLabel;
private
{ Private declarations }
public
{ Public declarations }
end; procedure getdata(ncount:integer;s:string);var
Form3: TForm3;implementation{$R *.dfm}type
TtableThread = class(TThread)
private
Ftable:ttable;
FtableException: Exception;
procedure tableError;protected
procedure Execute; override;
public
constructor Create(t: Ttable); virtual;end;constructor TtableThread.Create(t: Ttable);
begin
inherited Create(True); // create suspended thread
Ftable := t; // set parameters
FreeOnTerminate := True;
Resume; // thread that puppy!
end;procedure TtableThread.Execute;
begin
try except
FtableException := ExceptObject as Exception;
Synchronize(tableError); // show exception from main thread
end;
end;
procedure TtableThread.tableError;
begin
Application.ShowException(ftableException);
end;//---------以下为取得数据插入到数据库,是关键,里面的判断出错还需要根据条件----------
//---------变化更改,对于警告值需要改,看使用情况-------------------------procedure getdata(ncount:integer;s:string);var
i,insertsecond:integer;
Hour, Minute, Second, sSecond : word;
begin
with form3 do with table1 do begin
TtableThread.Create(table1);
active:=true;
last;
for i := 0 to nCount-1 do
begin
insert; fieldbyname('time').Value:= formatdatetime('hh:nn:ss',now); DecodeTime( now, Hour, Minute, Second, sSecond );
insertsecond:=hour*3600+minute*60+second;
fieldbyname('second').Value:=insertsecond; FieldByName('cs_id').value := Copy(s,i*26+1,11); begin
if (copy(s,i*26+13,7)=' -- ') or (copy(s,i*26+13,7)=' ') or (copy(s,i*26+13,7)=', --')or (copy(s,i*26+13,7)=', 0.00') then
FieldByname('tb').Value :=0
else
FieldByname('tb').AsString := copy(s,i*26+13,7);
end;
begin
if ((Copy(s,i*26+21,4)=' --') or (Copy(s,i*26+21,4)=' -- ')or (Copy(s,i*26+21,4)=' >85')) then
FieldByname('cq').Value :=0
else
FieldByname('cq').AsString := Copy(s,i*26+21,4);
end;
end;
post;
end;
end;
end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DBCtrls, Grids, DBGrids, StdCtrls, DB, ADODB, DBTables;type
TForm3 = class(TForm)
Button1: TButton;
Session1: TSession;
Database1: TDatabase;
Table1: TTable;
Memo1: TMemo;
Label1: TLabel;
private
{ Private declarations }
public
{ Public declarations }
end; procedure getdata(ncount:integer;s:string);var
Form3: TForm3;implementation{$R *.dfm}type
TtableThread = class(TThread)
private
Ftable:ttable;
FtableException: Exception;
procedure tableError;protected
procedure Execute; override;
public
constructor Create(t: Ttable); virtual;end;constructor TtableThread.Create(t: Ttable);
begin
inherited Create(True); // create suspended thread
Ftable := t; // set parameters
FreeOnTerminate := True;
Resume; // thread that puppy!
end;procedure TtableThread.Execute;
begin
try except
FtableException := ExceptObject as Exception;
Synchronize(tableError); // show exception from main thread
end;
end;
procedure TtableThread.tableError;
begin
Application.ShowException(ftableException);
end;//---------以下为取得数据插入到数据库,是关键,里面的判断出错还需要根据条件----------
//---------变化更改,对于警告值需要改,看使用情况-------------------------procedure getdata(ncount:integer;s:string);var
i,insertsecond:integer;
Hour, Minute, Second, sSecond : word;
begin
with form3 do with table1 do begin
TtableThread.Create(table1);
active:=true;
last;
for i := 0 to nCount-1 do
begin
insert; fieldbyname('time').Value:= formatdatetime('hh:nn:ss',now); DecodeTime( now, Hour, Minute, Second, sSecond );
insertsecond:=hour*3600+minute*60+second;
fieldbyname('second').Value:=insertsecond; FieldByName('cs_id').value := Copy(s,i*26+1,11); begin
if (copy(s,i*26+13,7)=' -- ') or (copy(s,i*26+13,7)=' ') or (copy(s,i*26+13,7)=', --')or (copy(s,i*26+13,7)=', 0.00') then
FieldByname('tb').Value :=0
else
FieldByname('tb').AsString := copy(s,i*26+13,7);
end;
begin
if ((Copy(s,i*26+21,4)=' --') or (Copy(s,i*26+21,4)=' -- ')or (Copy(s,i*26+21,4)=' >85')) then
FieldByname('cq').Value :=0
else
FieldByname('cq').AsString := Copy(s,i*26+21,4);
end;
end;
post;
end;
end;
end.
添加 SESSION,DATABASE ,TABLE 控件,如何提高才具速度,谢谢,
采集的是上面的数据,目前可以使用,
主要程序如下,
with table1 do begin
TtableThread.Create(table1);
active:=true;
last;
for i := 0 to nCount-1 do
begin
insert; fieldbyname('time').Value:= formatdatetime('hh:nn:ss',now); FieldByname('cq').AsString := Copy(s,i*26+21,4);
FieldByname('tb').AsString := copy(s,i*26+13,7);
FieldByname('cq').AsString := Copy(s,i*26+21,4);
这四个列是ACCESS里的一张表,上面程序多了写其他的条件判断,不过主要实现
还是这几条,关键是我的线程使用是否有错,我的速度不够快,要等待,出现SQL等待
是用猫采的,也是放在库里,后来改了一下,
他用的是VC,
我想主要是要做到:
采集的时候先放在内存,不要写库,他用的是文件,然后展开,
你可以用TClientDataSet,(但不是远程数据库)因为嘛,它有个作用,
loadfromfile
把一个库一下子都读到内存里了,,
再最后,当然Savetofile了,然后,在线程里对TCLIENTDATASET进行操作,你再看看,
保证速度可以提高几个等级,
LUCK!
还是写错了,是5ms,但我的方法要求,内存不能太小啦,<16M
中间不能停电,哈哈,线程里最后不要做什么POST,ROLLBACK一类,
那本身就快不了
809B8540034, 0.000,45.6
809B8440044, 8.754,25.8
809B8540324, 18.124,23.3
809B8540014, 19.376,42.3
890B8540384, 23.124,21.8
809B8540104, 23.752,18.3
809B8540214, 24.377,27.0
809B8540134, 25.002,19.1
809B8540244, 33.126,26.3
809B8540364, 33.756,19.8
809B8540084, 40.003,29.6
809B8540234, 43.124,32.0
809B8440334, 50.000,23.6
809B8940214, 53.754,19.1
809B8440344, 54.375,22.1
809B8440314, 55.005,18.0
809B8440324, 63.752,13.6
809B8540154, 64.377,23.0
809B8940314, 68.136,18.3
809B8540174, 74.377,20.3
809B8440054, 79.374,24.0
809B8440084, 83.754,28.1
809B8440114, 85.005,21.6
809B8440204, 88.126,15.8
809B8540274, 93.751,30.3
809B8540094, 94.371,18.0
809B8940284, 98.130,20.6
是不是写在 TXT里,然后再用COPY 到库里,吗,
还是什么意思,不明白,对不起,
那本身就快不了那用什么办法呢,怎么能产生停下,
设备是死的,一下子来了,很多数据,我如何能使数据读到数据库
合适点,谢谢,
一下,你的线程不用改
或者是写成一个文件,先不要在数据库中写,也就是不用POST之类
两种方案你可以先试试第一种,因为改动不太大
是可以的,不过,TXT不行,要用STREAM才行,
总之,线程只对内存写,最后一起写到数据库里
with query do
begin
sql.clear;
sql.sql.add('insert into table values(:param1,:param2...)');
params[0].asString := ..
...
executeSql;
end;
。另外,database要一直保持连接,这样速度会比较快。
是可以的,不过,TXT不行,要用STREAM才行,
总之,线程只对内存写,最后一起写到数据库里我的数据 是一下子出来,然后我5秒,或更快一点发一条指令,
每发一次,出来大概就上面那么多,或更多一点,
不过他是一下子出来一个数据串,怎么能提高速度呢,
为什么它能一下子出来这么多数据,不是比你的机子还快吧,
你在线程里写插入动作太慢了,
先写到内存里不行么?
。。如何把上面我的条件加上去呢,
把数据源用TClientDataSet,用线程之前先loadfromfile
一下,你的线程不用改
因为TClientDataSet把数据能放在内存里,你可以用它的loadfromfile功能
就不用写代码写什么内存了,
其它的地方不用改
我的MAIL,[email protected]
再有问题MAIL吧,