我
我人很笨
Unregistered / Unconfirmed
GUEST, unregistred user!
我自定义了一个函数 getspbh 用来得到编号。但是做了个edit1,当修改的时候调用。问题就是当我点修改按钮时候,edit1没有得到编号<br>代码如下<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> ADOQuery1: TADOQuery;<br> ADOConnection1: TADOConnection;<br> DataSource1: TDataSource;<br> DBGrid1: TDBGrid;<br> Button1: TButton;<br> Button2: TButton;<br> Edit1: TEdit;<br> Edit2: TEdit;<br> procedure FormShow(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> procedure getspbh(sender:Tobject);<br> private<br> { Private declarations }<br> public<br> spbh:string;<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br>procedure Tform1.getspbh(sender:Tobject); //得到商品编号<br>begin<br> adoquery1.Last;<br> if adoquery1.RecordCount=0 then<br> spbh:='T'+formatfloat('00000',1)<br> else<br> spbh:='T'+Formatfloat('00000',strtoint(copy(adoquery1.Fields[0].AsString,2,5))+1);<br>end;<br>procedure TForm1.FormShow(Sender: TObject);<br>begin<br>with adoquery1 do<br>begin<br>close;<br>sql.Clear;<br>sql.Add('select * from 种类');<br>open;<br>end;<br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>form1.getspbh(sender);<br>edit1.Text:=form1.spbh;<br>with adoquery1 do<br> begin<br> close;<br> sql.Clear;<br> sql.Add('insert into 种类(种类名称)');<br> sql.Add('values种类名称)');<br> parameters.ParamByName('种类名称').Value := trim(edit2.Text);<br> try<br> execsql;<br> close;<br> sql.Clear;<br> sql.Add('select * from 种类');<br> open;<br> application.MessageBox('增加成功!', '提示!', mb_ok + mb_iconinformation);<br> except<br> end;<br> end;<br>end;<br><br>end.