我在两个窗口里做相同的数据添加的工作,而且也是对同一个表进行操作,为什么一个快,一个慢?哪个高手帮忙看看程序到底哪里有问题呢?代码如下:添加速度 较快 的代码:
procedure TFrmTotal.N13Click(Sender: TObject);
var
sum1, sum2, sum3, sum4: integer;
sum: double;
s, s1, s2, s3: string;
begin
s1 := DBGridEh3.Columns[4].DisplayText;
s2 := DBGridEh3.Columns[3].DisplayText;
with DataModule2.AqryEquipmentTotal do
begin
Close;
sql.clear;
sql.Add('select * from stmgequipment where einc=' + quotedstr(s1) + 'and process=' + quotedstr(s2));
Open;
if RecordCount <= 0 then
begin
Application.MessageBox('工序名称或设备号在基础库中不存在,请与定额管理室联系后再操作!', '系统提示', 64 + 0);
DBGridEh3.DataSource.DataSet.Cancel;
DBGridEh3.Options := DBGridEh3.Options + [dgRowSelect] - [dgEditing];
exit;
end;
end;
sum := 0;
if (Aqrystmgcountdetail.State = dsEdit) or (Aqrystmgcountdetail.State = dsInsert) then
begin
if DBGridEh3.DataSource.DataSet.fieldbyname('stint_time_h').AsFloat = null then
DBGridEh3.DataSource.DataSet.fieldbyname('stint_time_h').AsFloat := 0;
if DBGridEh3.DataSource.DataSet.fieldbyname('stint_time_m').AsFloat = null then
DBGridEh3.DataSource.DataSet.fieldbyname('stint_time_m').AsFloat := 0;
DBGridEh3.DataSource.DataSet.post;
s := DBEditEh1.Text;
with Aqrystmgcountdetail do
begin
locate('id', s, [loPartialKey]);
end;
end;
DBGridEh3.Options := DBGridEh3.Options + [dgRowSelect] - [dgEditing];
end;添加速度 较慢 的代码:
procedure TFrmFind.N2Click(Sender: TObject);
var
sum1, sum2, sum3, sum4: integer;
sum : double;
s, s1, s2, s3 : string;
i, count : integer;
begin
s1 := DBGridEh2.Columns[4].DisplayText;
s2 := DBGridEh2.Columns[3].DisplayText;
with DataModule2.AqryEquipmentTotal do
begin
Close;
sql.clear;
sql.Add('select * from stmgequipment where einc=' + quotedstr(s1) + 'and process=' + quotedstr(s2));
Open;
if RecordCount <= 0 then
begin
Application.MessageBox('工序名称或设备号在基础库中不存在,请与定额管理室联系后再操作!', '系统提示', 64 + 0);
DBGridEh2.DataSource.DataSet.Cancel;
DBGridEh2.Options := DBGridEh2.Options + [dgRowSelect] - [dgEditing];
exit;
end;
end;
sum := 0;
if (AqryDetaiL.State = dsEdit) or (AqryDetaiL.State = dsInsert) then
begin
if DBGridEh2.DataSource.DataSet.fieldbyname('stint_time_h').AsFloat = null then
DBGridEh2.DataSource.DataSet.fieldbyname('stint_time_h').AsFloat := 0;
if DBGridEh2.DataSource.DataSet.fieldbyname('stint_time_m').AsFloat = null then
DBGridEh2.DataSource.DataSet.fieldbyname('stint_time_m').AsFloat := 0;
DBGridEh2.DataSource.DataSet.post;
s := DBEditEh1.Text;
with AqryDetaiL do
begin
locate('id', s, [loPartialKey]);
end;
end;
DBGridEh2.Options := DBGridEh2.Options + [dgRowSelect] - [dgEditing];
end;以上两段代码基本一致,为何速度相差甚远,高手帮忙吧!
procedure TFrmTotal.N13Click(Sender: TObject);
var
sum1, sum2, sum3, sum4: integer;
sum: double;
s, s1, s2, s3: string;
begin
s1 := DBGridEh3.Columns[4].DisplayText;
s2 := DBGridEh3.Columns[3].DisplayText;
with DataModule2.AqryEquipmentTotal do
begin
Close;
sql.clear;
sql.Add('select * from stmgequipment where einc=' + quotedstr(s1) + 'and process=' + quotedstr(s2));
Open;
if RecordCount <= 0 then
begin
Application.MessageBox('工序名称或设备号在基础库中不存在,请与定额管理室联系后再操作!', '系统提示', 64 + 0);
DBGridEh3.DataSource.DataSet.Cancel;
DBGridEh3.Options := DBGridEh3.Options + [dgRowSelect] - [dgEditing];
exit;
end;
end;
sum := 0;
if (Aqrystmgcountdetail.State = dsEdit) or (Aqrystmgcountdetail.State = dsInsert) then
begin
if DBGridEh3.DataSource.DataSet.fieldbyname('stint_time_h').AsFloat = null then
DBGridEh3.DataSource.DataSet.fieldbyname('stint_time_h').AsFloat := 0;
if DBGridEh3.DataSource.DataSet.fieldbyname('stint_time_m').AsFloat = null then
DBGridEh3.DataSource.DataSet.fieldbyname('stint_time_m').AsFloat := 0;
DBGridEh3.DataSource.DataSet.post;
s := DBEditEh1.Text;
with Aqrystmgcountdetail do
begin
locate('id', s, [loPartialKey]);
end;
end;
DBGridEh3.Options := DBGridEh3.Options + [dgRowSelect] - [dgEditing];
end;添加速度 较慢 的代码:
procedure TFrmFind.N2Click(Sender: TObject);
var
sum1, sum2, sum3, sum4: integer;
sum : double;
s, s1, s2, s3 : string;
i, count : integer;
begin
s1 := DBGridEh2.Columns[4].DisplayText;
s2 := DBGridEh2.Columns[3].DisplayText;
with DataModule2.AqryEquipmentTotal do
begin
Close;
sql.clear;
sql.Add('select * from stmgequipment where einc=' + quotedstr(s1) + 'and process=' + quotedstr(s2));
Open;
if RecordCount <= 0 then
begin
Application.MessageBox('工序名称或设备号在基础库中不存在,请与定额管理室联系后再操作!', '系统提示', 64 + 0);
DBGridEh2.DataSource.DataSet.Cancel;
DBGridEh2.Options := DBGridEh2.Options + [dgRowSelect] - [dgEditing];
exit;
end;
end;
sum := 0;
if (AqryDetaiL.State = dsEdit) or (AqryDetaiL.State = dsInsert) then
begin
if DBGridEh2.DataSource.DataSet.fieldbyname('stint_time_h').AsFloat = null then
DBGridEh2.DataSource.DataSet.fieldbyname('stint_time_h').AsFloat := 0;
if DBGridEh2.DataSource.DataSet.fieldbyname('stint_time_m').AsFloat = null then
DBGridEh2.DataSource.DataSet.fieldbyname('stint_time_m').AsFloat := 0;
DBGridEh2.DataSource.DataSet.post;
s := DBEditEh1.Text;
with AqryDetaiL do
begin
locate('id', s, [loPartialKey]);
end;
end;
DBGridEh2.Options := DBGridEh2.Options + [dgRowSelect] - [dgEditing];
end;以上两段代码基本一致,为何速度相差甚远,高手帮忙吧!
解决方案 »
- delphi那个版本支持64位系统,现在出来了没?
- 日期函数的问题
- 我最近做了一个Shell扩展,不知道怎么调试?
- 从BDE通过ADO连接access200,对数据库(Access)的更新操作出现了"[Microsoft][ODBC Microsoft Access Driver]非法的精确读数值"的提示?
- 各位大大,有没有AUTOCAD文件的控件啊,最近我要写一个数据库,对公司产品开发数据进行管理
- 如何将两个TShape做成一个组件?
- 用delphi开发asp组件。组件写完后,怎样打包成安装程序。
- 怎么实现将指定的文本文件导入excel指定单元格
- 为什么写ISAPI的喜欢用VC++, 而不用Delphi?
- 李维说对于多个表的Query的更新ADO强于BDE,我觉得不是
- 高分救人!使用spcomm控件和下位机通讯,下面每10ms发一帧数据上来,我如何区分每一帧数据
- 还是关于Delphi 返回类型的问题
如果数据量不同,那么locate的速度是有差别的。与你插入还是保存没有太大的关系(操作同一个表)
建议:相同代码,不同变量,可以提炼出一个过程。这样便于调试和发现问题,加强工作效率。
在代码上看不出来.赞同SmallHand:"建议:相同代码,不同变量,可以提炼出一个过程。这样便于调试和发现问题,加强工作效率。"
又测了一下,设置了几处断点,发现慢的过程是发生在DBGridEh3.DataSource.DataSet.post;之后,而在locate的时候是很快的,问题应该是出在了哪里呢?