用Indy写了一个即时通讯的小软件,IdtcpServer创建的多线程操作数据库中,查了论坛里的资料了解到应该每一线程创建一个AdoConnectin连接通过AdoQuery来操作数据库,但是都没有实际的代码,应该怎么来写才行正确的创建和释放,有没有实际代码啊。谢谢了!
解决方案 »
- 求助,有关剪裁图片
- DELPHI向隐藏的窗口发送按键,
- TListView控件的Item能不能给加一个属性(类似于Name)?
- 如何检测字符串中是否有某些字符
- 李维D5 ADO/MTS/COM+高级程序设计书中几个不明白的问题
- UP有分!! 请大家帮忙分析一下!!!
- 关于Sql Server的系统表??
- 有用过FORM.PRINT的吗?打印结果是什么样的?
- 在deiphi如何调用以下DOS的以下命令?
- 各位兄弟,一个关于mediaplayer的问题,帮帮忙,在下先行谢过
- 新手问题:用ListView控件,怎么知道它的数据行数???在线等!
- 我用了VCLSKIN,auoscroll条就看不见了,怎么办啊。
//由主窗口传入一个TAdoDataset组件和ListView组件,若查询到结果就显示在主窗口的listview组件中.unit Unit2;interfaceuses
Classes,DB,AdoDB,ComCtrls,SysUtils;type
TQueryThread = class(TThread)
private
{ Private declarations }
FDataSet:TAdoDataset;
FQueryException:Exception;
ListView:TListview;
procedure UpdateListView;
protected
procedure Execute; override;
public
constructor Create(Q:TAdoDataSet;LV:TListview); virtual;
end;implementation
uses
windows,unit3;{ TQueryThread }constructor TQueryThread.Create(Q: TAdoDataSet;LV:TListview);
begin
inherited Create(true);
ListView:=LV;
FDataSet := Q;
FDataset.CommandText :='SELECT * FROM TABLE'
FreeOnTerminate:=true;
Resume;
end;
procedure TQueryThread.Execute;
begin
try
FDataset.Open;
if not FdataSet.IsEmpty then
begin
synchronize(Updatelistview);
end;
except
FqueryException:=ExceptObject as Exception;
raise FqueryException.Create('查找过程出错');
end;
end;procedure TQueryThread.UpdateListView;
var
listItem:TlistItem;
begin
with listview do
begin
while not Fdataset.eof do
begin
listitem:=items.add;
listitem.Caption :='..... '
listitem.SubItems.Add(Fdataset.fieldbyname('A').asstring);
listitem.SubItems.Add(Fdataset.fieldbyname('Br').asstring);
//.......
Fdataset.next;
end;
end;
end;end.