想要实现的效果:程序在打开新建按钮后,编号自动加上一
思路:在点击新建后,程序自动移至最后一条纪录,并且把这条纪录的编号取出,赋予一个变量,然后变量+1,再回写到数据库里面代码:procedure TForm1.ToolButton1Click(Sender: TObject);
var
m:string;
n:integer;
begin
while not adotable1.Eof do //检测数据表指针是否已指向末位
begin
adotable1.Next;
end;
begin
adotable1.Active:=true;
with adotable1 do
begin
m:=FieldValues['订单号']; //复制上一条记录
n:=(strtoint(m)+1);
edit20.Text:=inttostr(n)
end;
end;但我代码执行下来不对,它只是把第一条纪录的数值取出,而不是我要的最后一条,哪位知道为什么会出现这个情况的?
思路:在点击新建后,程序自动移至最后一条纪录,并且把这条纪录的编号取出,赋予一个变量,然后变量+1,再回写到数据库里面代码:procedure TForm1.ToolButton1Click(Sender: TObject);
var
m:string;
n:integer;
begin
while not adotable1.Eof do //检测数据表指针是否已指向末位
begin
adotable1.Next;
end;
begin
adotable1.Active:=true;
with adotable1 do
begin
m:=FieldValues['订单号']; //复制上一条记录
n:=(strtoint(m)+1);
edit20.Text:=inttostr(n)
end;
end;但我代码执行下来不对,它只是把第一条纪录的数值取出,而不是我要的最后一条,哪位知道为什么会出现这个情况的?
解决方案 »
- 求 一个登录界面代码
- 求delphi5下载地址
- 关于函数的问题
- 谁有公交换乘的算法?或思路? 求教!万分感谢!
- 着急啊,帮忙啊,字符串转换的问题
- 在WebSnap技术中如何将做好的Grid嵌入已做好的html模板中,我知道InternetExpress的使用方法,但不知道WebSnap技术如何实现
- 如何使用adostoredproc,可以举的例子吗?!谢谢各位大哥
- Delphi 与 C++ Builder 之比较
- 请问PAGECONTROL的标题怎么加上颜色
- a:=insert('000',edit2.text,6); 这句代码哪里错了?
- 短暂快乐的另一半就是没完没了的烦恼。。。
- 高手都进来帮忙一下。。。大家都来发扬一下程序员互助的精神。。分不够我在加。
m:string;
n:integer;
begin
adotable1.Active:=true;//--------1
while not adotable1.Eof do //检测数据表指针是否已指向末位
begin
adotable1.Next;
end;
begin
// adotable1.Active:=true;//-----------2
with adotable1 do
begin
m:=FieldValues['订单号']; //复制上一条记录
n:=(strtoint(m)+1);
edit20.Text:=inttostr(n)
end;
end;1处:adotable1 未打开,没有记录 故adotable1.Eof 为true
应该先打开 adotable1
while not adotable1.Eof do //检测数据表指针是否已指向末位
begin
adotable1.Next;
end;
table1.open;
table1.last;
然后取值即可
var
m:string;
n:integer;
begin
with adotable1 do
begin
Open;
Last;
m:=FieldValues['订单号']; //复制上一条记录
n:=(strtoint(m)+1);
edit20.Text:=inttostr(n)
end;
end;