检索后修改值(100分)

  • 主题发起人 主题发起人 tanghz
  • 开始时间 开始时间
T

tanghz

Unregistered / Unconfirmed
GUEST, unregistred user!
我打算对一个库先通过
检索到编号为

table1[`no`]=temp[2] 的项时,
执行
with table1 do begin
.....

1 edit;
2 table1['gbacc']:=table1['gbacc']+temparray[2];
3 post;
4 end;
但是,最终的结果是gbacc 这一栏什么也没有。
谁能解决此问题?
 
如果是字符串字段:
....
table1.fieldbyname('gbacc').asstring {或者asInteger, asFloat, asCurrency} :=
table1.fieldbyname('gbacc').asstring // 或者asstring, asfloat, ascurrency
// 视temparray的类型而定
+ temparray[2];
.....
 
非常感谢及时回复,的确成功了。但是为什么?
另外,我用locate 做的检索,大概有1万多条纪录,越到后来越慢。
这是一个Paradox table, 主key是No。 (numeric)。是否有什么好的方法加速检索。
 
对你需要检索的字段添加索引,然后用Findkey来查找,尽量少用Locate,他要遍历整个表.
 
to wgzhang:
不对吧,李维的delphi3从入门到精通说locate是查找速度最快的(borland推荐
使用),有索引的话,它会自动按索引找的。
 
对!
不过, ID为什么不用整形?会快很多!
注意整理你的表(pack it).
 
如果不用.asstring指定类型的话,
表中返回的是一个变体变量,
运算后再往表里存的时候,
系统不知道该将这个变量按哪种类型蹲进去
所以就可能存为空值
 
用query吧, 最快了:-)
 
TO :hubdog 的确,我也见到书中这样写,
TO :wgzhang如果用Findkey, 这段代码如何写?


begin
editkey;
table1.FieldByName('locusid').asstring:=temparray[1];
if gotokey then
begin
table1.edit ;
table1.FieldByName('gbacc').asstring:=table1.FieldByName('gbacc').asstring+temparray[2];
post;
end;

我试过这段代码,但根本不工作。
 
感谢大家的参与,我打算提出另一问题。
利用Delphi的Richtext 作为模板建立的文字处理软件,
问什么一遇到大文件〉1MB,就只能读,不能修改,保存。
 
注意:字段locusid要有索引,并且当前索引为此索引.
if Table1.FindKey([temparray[1]]) then
begin
table1.edit ;
table1.FieldByName('gbacc').asstring:=table1.FieldByName('gbacc').asstring+temparray[2];
table1.post;
end;
 
后退
顶部