怎样处理线程问题,timer控件扫描时,线程没有处理完,怎样修改 ( 积分: 0 )

  • 主题发起人 主题发起人 xsgdhjt
  • 开始时间 开始时间
X

xsgdhjt

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TMain_Frm.Timer_rkTimer(Sender: TObject);
var
s:string;
path,patch1:pchar;
f,cw:textfile;
begin
Timer_rk.enabled:=false;
try
path:=pchar('d:/jzdata/qxdata');
copyfile(path,'d:/jzdata/chuli/qxdata',false);
copyfile(path,'d:/jzdata/oracle/qxdata',false);
assignfile(f,'d:/jzdata/qxdata');
rewrite(f);
closefile(f);
path:=pchar('d:/jzdata/cwdata');
copyfile(path,'d:/jzdata/chuli/cwdata',false);
copyfile(path,'d:/jzdata/oracle/cwdata',false);
assignfile(cw,'d:/jzdata/cwdata');
rewrite(cw);
closefile(cw);
oracelsjclthread.create(false);
finally
timer_rk.Enabled:=true;
end;
end;


procedure oracelsjclthread.Execute;
var
str:string;
//path:pchar;
orlqx,orlcw,f,cw:textfile;
riqi:string;
dt: tdatetime;
linename:string;
linenum:string;
towernum:string;
obj:string;
begin
Main_Frm.Timer_rk.enabled:=false;
//################################################################################### ---092306

AssignFile(orlqx,'d:/jzdata/oracle/qxdata'); //固定路径 "d:/bddata"
reset(orlqx);
while not eof(orlqx) do
begin //1
readln(orlqx,str);
riqi:=copy(str,1,2)+'-'+copy(str,3,2)+'-'+copy(str,5,3)+' '+copy(str,8,3)+':'+copy(str,11,3);
obj:=copy(str,39,11);
if TryStrToDateTime(riqi,dt) then
//begin
//xt_DataModule.query_sim.Active:=true;
//if xt_DataModule.query_sim.Locate('shouji_Num',copy(str,39,11),[loCaseInsensitive]) then
begin //4
with DM.table_qxdata do //oracle数据库
begin //2
close;
ReadOnly:=false;
open;
insert;
fieldbyname('MonNo').AsString:=obj;
{linenum:=xt_DataModule.query_sim.fieldbyname('line_num').asstring;
with xt_DataModule.ADOQuery1 do
begin
SQL.clear;
SQL.add('select line_name');
SQL.add('from line b');
SQL.Add('where b.line_num =:b.num ');
Parameters.ParamByName('b.num').Value:=linenum;
active:=true;
end;
linename:=xt_DataModule.ADOQuery1.Fields[0].asstring;
towernum:=xt_DataModule.query_sim.fieldbyname('tower_num').asstring;}
//fieldbyname('MonNo').AsString:=linename+towernum;
//fieldbyname('objNo').AsString:=linename+towernum;
fieldbyname('RdTime').AsDateTime:=dt;
fieldbyname('MonNo').AsString:=getobjno(obj);
fieldbyname('objNo').AsString:=getobjno(obj);;
fieldbyname('temp').AsInteger:=strtoint(copy(str,14,3))-50;
fieldbyname('humid').AsInteger:=strtoint(copy(str,17,3));
fieldbyname('windspeed').AsInteger:=strtoint(copy(str,20,3));
//fieldbyname('winddir').Asstring:=Getfx(copy(str,24,2));
fieldbyname('winddir').AsInteger:=strtoint(copy(str,23,3));
fieldbyname('rnfallvol').AsInteger:=strtoint(copy(str,26,3));
fieldbyname('airpress').AsInteger:=strtoint(copy(str,29,4));
//fieldbyname('rz').AsInteger:=strtoint(copy(str,33,3));
fieldbyname('battvol').AsFloat:=strtoint(copy(str,36,3))/10;
post;
end; //2
//end;
end
else
continue; //4
end; //1
rewrite(orlqx); //清空.txt
closefile(orlqx);
//###################################################################################
//################################################################################### ---092306
AssignFile(f,'d:/jzdata/chuli/qxdata'); //固定路径 "d:/bddata"
reset(f);
while not eof(f) do
begin //1
readln(f,str);
riqi:=copy(str,1,2)+'-'+copy(str,3,2)+'-'+copy(str,5,3)+' '+copy(str,8,3)+':'+copy(str,11,3);
if TryStrToDateTime(riqi,dt) then
begin
xt_DataModule.query_sim.Active:=true;
if xt_DataModule.query_sim.Locate('shouji_Num',copy(str,39,11),[loCaseInsensitive]) then
begin //4
with xt_DataModule.table_qxdata do //sql server数据库
begin //2
close;
ReadOnly:=false;
open;
insert;
fieldbyname('sj').AsDateTime:=dt;
//fieldbyname('sj').AsDateTime:=strtodatetime(copy(str,1,2)+'-'+copy(str,3,2)+'-'+copy(str,6,2)+' '+copy(str,9,2)+':'+copy(str,12,2));
fieldbyname('line_num').AsString:=xt_DataModule.query_sim.fieldbyname('line_num').asstring;
fieldbyname('tower').AsString:=xt_DataModule.query_sim.fieldbyname('tower_num').asstring;
fieldbyname('wd').AsInteger:=strtoint(copy(str,14,3))-50;
fieldbyname('sd').AsInteger:=strtoint(copy(str,17,3));
fieldbyname('fs').AsInteger:=strtoint(copy(str,20,3));
fieldbyname('fx').Asstring:=Getfx(copy(str,23,3));
fieldbyname('yl').AsInteger:=strtoint(copy(str,26,3));
fieldbyname('qy').AsInteger:=strtoint(copy(str,29,4));
fieldbyname('rz').AsInteger:=strtoint(copy(str,33,3));
fieldbyname('dy').AsFloat:=strtoint(copy(str,36,3))/10;
post;
end; //2
end;
end
else
continue; //4
end; //1
rewrite(f); //清空.txt
closefile(f);

//###################################################################################
Main_Frm.Timer_rk.Enabled:=true;
end;
 
程序启动时建一个线程,定时去读这个文件,记得程序结束时,释放这个线程。
 
后退
顶部