//因为要创建一个操作会比较繁忙的服务程序,ADO控件的不安全性,让我没有办法,只有在线程中创建,用完了再销毁。
//结果我现在只是测试一下,我用计时器不停地触发线程(每毫秒一次),结果,平均不到20秒,程序就崩溃,弹出这样的对消息。
//Project TestS.exe rased exception class EaccessViolation with message 'Access violation at address 004236F6 in module 'TestS.exe'. Read of address 00000008. Process stopped. Use Setp or Run to continue.
//真是郁闷,请各位大侠帮我看看,这是什么原因?
//开始我用Free销毁控件,好像会死得更快些,后来改用Destory好像要时间长一点,但还是一样,会崩溃。
//我把计时器调用100毫秒,可以运行1-3分钟左右,但也会死,所以我觉得这并不像是一般的简单性问题,像各位大侠致敬,谢谢!procedure SendUDPThread.Execute();
var
AdoConn1:TADOConnection;
AdoQuery1:TAdoQuery;
begin
try
Lock.Enter;
AdoConn1:=TADOConnection.Create(Form1); //动态创建ADO控件
AdoConn1.ConnectionString:=Form1.ADOConnection1.ConnectionString;
AdoConn1.LoginPrompt:=false;
AdoQuery1:=TAdoQuery.Create(Form1);
AdoQuery1.Connection:=AdoConn1; with AdoQuery1 do
begin
SQL.Add('select * from Users where id='+inttostr(RecordID)+' order by id desc'); //RecordID是我在线程创建时定义的一个私有变量
open;
While not eof do
begin
Form1.Memo1.Lines.Add(FieldByName('Name').AsString);
next;
end;
end; Form1.Memo1.Lines.Add('处理成功.');
Lock.Leave;
AdoConn1.Close;
AdoQuery1.Destroy;
AdoConn1.Destroy;//消除
except
Lock.Leave;
AdoConn1.Destroy;
AdoQuery1.Destroy;
Form1.Memo1.Lines.Add('处理失败.');
end;
end;
//结果我现在只是测试一下,我用计时器不停地触发线程(每毫秒一次),结果,平均不到20秒,程序就崩溃,弹出这样的对消息。
//Project TestS.exe rased exception class EaccessViolation with message 'Access violation at address 004236F6 in module 'TestS.exe'. Read of address 00000008. Process stopped. Use Setp or Run to continue.
//真是郁闷,请各位大侠帮我看看,这是什么原因?
//开始我用Free销毁控件,好像会死得更快些,后来改用Destory好像要时间长一点,但还是一样,会崩溃。
//我把计时器调用100毫秒,可以运行1-3分钟左右,但也会死,所以我觉得这并不像是一般的简单性问题,像各位大侠致敬,谢谢!procedure SendUDPThread.Execute();
var
AdoConn1:TADOConnection;
AdoQuery1:TAdoQuery;
begin
try
Lock.Enter;
AdoConn1:=TADOConnection.Create(Form1); //动态创建ADO控件
AdoConn1.ConnectionString:=Form1.ADOConnection1.ConnectionString;
AdoConn1.LoginPrompt:=false;
AdoQuery1:=TAdoQuery.Create(Form1);
AdoQuery1.Connection:=AdoConn1; with AdoQuery1 do
begin
SQL.Add('select * from Users where id='+inttostr(RecordID)+' order by id desc'); //RecordID是我在线程创建时定义的一个私有变量
open;
While not eof do
begin
Form1.Memo1.Lines.Add(FieldByName('Name').AsString);
next;
end;
end; Form1.Memo1.Lines.Add('处理成功.');
Lock.Leave;
AdoConn1.Close;
AdoQuery1.Destroy;
AdoConn1.Destroy;//消除
except
Lock.Leave;
AdoConn1.Destroy;
AdoQuery1.Destroy;
Form1.Memo1.Lines.Add('处理失败.');
end;
end;
//原来是我自己把这个弄错了呀!!我改了一下好像搞掂了!
AdoConn1:=TADOConnection.Create(nil);
这一部分代码尚未修改,也就是说现在仍然引用的是Form1.AdoConnection1.ConnetionString,我只是把Create(Aowner)修改了一下,目前已经运行了将近5分钟,触发时间仍然是一毫秒,尚未出现什么问题,所以我估计这个应该没问题。谢谢你的关注!