我想写一个线程,线程功能:从远程数据库实时下载数据到本地库,
在程序运行时这个线程就运行,在程序退出时才中断,而且在程序运行的
时候还要考虑掉线的故障,如果网断了那么就每隔一段时间连接一次远程数据库,
连上了线程再继续运行直到退出程序。谢啦!!!!!!!!!!!!!!!!!!!
在程序运行时这个线程就运行,在程序退出时才中断,而且在程序运行的
时候还要考虑掉线的故障,如果网断了那么就每隔一段时间连接一次远程数据库,
连上了线程再继续运行直到退出程序。谢啦!!!!!!!!!!!!!!!!!!!
使用的是 TADOConnection 加 TADOQuery注意:
在线程里不允许进行网络连接.会提示出错的.
解决办法是在开线程之前先进行数据连接.在线程里检测到 ADOConnection1.Connected 为假时就等待或者退出线程.
至于在程序运行的时候连接中断后如何再次连接数据库(线程内无法去连接),可以在主窗体上加一个 TTimer 控件.每隔一段时间去检查 ADOConnection1.Connected,检测到连接中断则再次连接数据库.
file://目录下载function tftp.ex_download(remote_dir,local_dir:string):boolean;vari,j,count1:integer;att,ss:string;current_dir:string;temp_dir:string;begintry beginNMFTP1.ChangeDir(remote_dir);current_dir:=remote_dir;temp_dir:=copy(current_dir,2,length(current_dir));if not DirectoryExists(local_dir) then CreateDir(local_dir);if not directoryexists(local_dir+temp_dir) then createdir(local_dir+temp_dir);nmftp1.ParseList:=true;NMftp1.list;count1:=nmftp1.FTPDirectoryList.name.Count;for i:=0 to count1-1 do beginfile://必须NMFTP1.ChangeDir(current_dir);nmftp1.list;ss:=nmftp1.FTPDirectoryList.name.Strings[i];att:=nmftp1.FTPDirectoryList.Attribute.Strings[i];if (copy(pchar(att),1,1)<>'d')and(copy(pchar(att),1,1)<>'D') then beginif not DirectoryExists(local_dir) then CreateDir(local_dir);NMFTP1.Download(current_dir+ss,local_dir+temp_dir+ss);endelse beginif not directoryexists(local_dir+temp_dir+ss) then createdir(local_dir+temp_dir+ss);file://递归调用ex_download(remote_dir+ss+',local_dir);end;end;result:=true;endexceptOn E:Exception do beginresult:=false;end;end;end;