delphi线程中动态创建ADO控件


本文整理自网络,侵删。

 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 xe8 中tidtcpclient的writeln编码变化

Delphi 创建文件夹并打开

自己写的app如何禁掉安卓锁屏

Delphi清除右下角的托盘上无用的托盘图标(刷新托盘)

Delphi twebbrowser静音

Delphi shellexecute 发送邮件

Delphi生成的webservice appdebug的程序,编译时出错

Delphi 如何按下esc键退出程序

Delphi 判断字符是否是汉字

Delphi tanimate组件

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...