多次重绘表格时出错
我用Indy的IdTCPClient 向 IdTCPServer 发送数据过去,然后想在IdTCPServer所在的机器向数据服务器插入发过来的数据,并刷新一下DBGrid上的数据,用ADOQuery1->Close和Open刷新。发一条二条没有问题,发送多条后,表格的列慢慢变形,最后出现下面这个图:
请问用什么方法可以让它不出错呢?
这个是代码:
String swp;
try
{
AContext->Connection->IOHandler->CheckForDisconnect(True,True);
AContext->Connection->IOHandler->DefStringEncoding=TEncoding::Default;
swp=AContext->Connection->IOHandler->ReadLn();
if(swp!="")
AContext->Connection->IOHandler->WriteLn("服务器已经收到您发来的信息:"+swp);
Memo1->Lines->Add(UTF8Encode(swp));
//ShowMessage(swp);
TBookmark yqw_BM;
yqw_BM=ADOQuery1->GetBookmark();
TADOQuery *pado=new TADOQuery(NULL);
pado->Connection=this->ADOConnection1;
String testSql="INSERT INTO hlfloor.dbo.DF_PF_D( \
DF_PF_M_CODE,DF_PF_M_TYPE, DF_PF_D_XH,NEED_FL) values ( \
'test','2',2, '√')";
pado->SQL->Add(testSql);
pado->ExecSQL();
delete pado;
ADOQuery1->Close();
ADOQuery1->Open();
/*
TBookmark yqw_BM; // 做标记,使当前记录不移动
yqw_BM = ADOQuery1->GetBookmark();
if(ADOQuery1->BookmarkValid(yqw_BM))
{
ADOQuery1->GotoBookmark(yqw_BM);
}
ADOQuery1->FreeBookmark(yqw_BM);
*/
//AContext->Connection->IOHandler->writel
//return;
}
catch(...)
{
}