本文整理自网络,侵删。
procedure SendUDPThread.Execute();
var
AdoConn1:TADOConnection;
AdoQuery1:TAdoQuery;
begin
try
Lock.Enter;
AdoConn1:=TADOConnection.Create(nil);//动态创建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;
相关阅读 >>
Delphi 测试 tstreamwriter、tstreamreader
更多相关阅读请进入《Delphi》频道 >>