delphi初学者求助程序问题
大家好,小女子是一个delphi初学者,很多东西都不太懂,最近照着书上敲了一个药品销售管理系统的代码,可是出了很多错,下面这段销售管理窗体unit FormSell;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, ADODB, DB;
type
TSell = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
ADOTable1: TADOTable;
ADOTable2: TADOTable;
DataSource1: TDataSource;
DataSource2: TDataSource;
ADOQuery1: TADOQuery;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure Edit4Exit(Sender: TObject);
procedure Button3Click(Sender: TObject);
// procedure Button4Click(Sender: TObject);
procedure DBGrid1CellClick(Column: TColumn);
procedure Button2Click(Sender: TObject);
procedure DBGrid2CellClick(Column: TColumn);
procedure Edit2Change(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Edit3Change(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Sell: TSell;
ID:String;
implementation
{$R *.dfm}
uses FormManage; //该窗体关闭后需要调用Manage窗体
//窗口关闭响应函数
procedure TSell.FormClose(Sender: TObject; var Action: TCloseAction);
begin
manage.show;
end;
//销售按钮响应函数
procedure TSell.Button1Click(Sender: TObject);
begin
//判断是否库存数大于顾客购买的数量
if Edit4.text>adotable2.fieldbyname('库存数').asstring
then
begin
showMessage('对不起,您选择的商品我们只有'+adotable2.fieldbyname('库存数').asstring+'件,请您重新输入!') ;
Edit4.setfocus; //将光标重新置回销售数量编辑框
end
else
begin
//如果通过判断则在销售情况表中追加记录
AdoTable1.Append;
AdoTable1.FieldValues['销售日期']:=Edit1.text;
AdoTable1.FieldValues['药品名称']:=Edit2.text;
AdoTable1.FieldValues['药品代码']:=Edit3.text;
AdoTable1.FieldValues['销售数量']:=Edit4.text;
AdoTable1.FieldValues['销售单价']:=Edit5.text;
AdoTable1.FieldValues['销售金额']:=Edit6.text;
AdoTable1.Post; //修改表以后更新操作
//要更改药品信息表中的数据
Adotable2.Edit;
//从原有的库存数中减去顾客购买的数量
Adotable2.FieldValues['库存数']:=Adotable2.FieldValues['库存数']-StrToInt(Edit4.Text);
Adotable2.Post;
//清空各编辑框
Edit2.Clear;
Edit3.Clear;
Edit4.Clear;
Edit5.Clear;
Edit6.Clear;
Edit7.Clear;
end
end;
//创建窗体响应函数
procedure TSell.FormCreate(Sender: TObject);
begin
//自动显示日
Edit1.Text:=DateToStr(Date);//类型转换函
Edit4.Clear;
Edit5.Clear;
Edit6.Clear;
Edit7.Clear;
end;
//离开销售数量编辑框的响应函数
procedure TSell.Edit4Exit(Sender: TObject);
begin
if Edit4.Text='' then
begin
showMessage('请输入您购买的药品数量');
Edit4.SetFocus;
end
else
//自动计算销售金额并显示在Edit6中
Edit6.Text:=FloatToStr(StrToFloat(Edit5.Text)*StrToFloat(Edit4.Text));
end;
//修改按钮的响应函数
procedure TSell.Button3Click(Sender: TObject);
begin
//将药品信息表所对应的记录置成编辑状态
AdoTable2.Edit;
AdoTable2.FieldValues['库存数']:=AdoTable2.FieldValues['库存数']+
AdoTable1.FieldValues['销售数量']-StrToInt(Edit4.Text);
//修改数量时,最终的库存=原有库存+修改前的值-修改后的值
Adotable2.Post;
//接下来对药品销售进行操作
Adotable1.Edit;
AdoTable1.FieldValues['销售日期']:=Edit1.text;
AdoTable1.FieldValues['药品名称']:=Edit2.text;
AdoTable1.FieldValues['药品代码']:=Edit3.text;
AdoTable1.FieldValues['销售数量']:=Edit4.text;
AdoTable1.FieldValues['销售单价']:=Edit5.text;
AdoTable1.FieldValues['销售金额']:=Edit6.Text;
Adotable1.Post;
//清空各编辑窗体
Edit2.Clear;
Edit3.Clear;
Edit4.Clear;
Edit5.Clear;
Edit6.Clear;
Edit7.Clear;
end;
//通过DBGird1选择销售信息
procedure TSell.DBGrid1CellClick(Column: TColumn);
begin
Edit1.text:=DateToStr(AdoTable1.FieldValues['销售日期']);
//通过药品代码的变化可以触发Edit3Change事件
Edit3.Text:=Adotable1.FieldValues['药品代码'];
Edit4.Text:=IntToStr(adotable1.FieldValues['销售数量']);
Edit6.Text:=FloatToStr(Adotable1.FieldValues['销售金额']);
end;
//退货按钮的响应函数
procedure TSell.Button2Click(Sender: TObject);
begin
AdoTable2.locate('药品代码',Edit3.text,[locaseinsensitive,lopartialkey]);
AdoTable2.edit;
//删除前恢复药品信息表中该药品的库存数
AdoTable2.FieldValues['库存数']:=AdoTable2.FieldValues['库存数']+StrToInt(Edit4.Text) ;
Adotable2.post;
Adotable1.delete;
end;
//通过选择药品信息中的不同记录项更新数据
procedure TSell.DBGrid2CellClick(Column: TColumn);
begin
//只需要改变药品的代码就可以更新销售窗体中的数据
Edit3.text:=AdoTable2.fieldValues['药品代码'];
Edit4.clear;
edit6.clear;
end;
//药品名称变化响应函数
procedure TSell.Edit2Change(Sender: TObject);
begin
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.ADD('select * from 药品信息 where 药品名称='''+edit2.text+'''');
adoquery1.open;
//更新销售窗体信息,触发Edit3change事件
edit5.text:=adoquery1.fieldbyname('销售单价').asstring;
edit3.text:=adoquery1.fieldbyname('药品代码').asstring;
end;
//返回按钮响应函数
procedure TSell.Button5Click(Sender: TObject);
begin
Sell.Close;
Manage.show;
end;
//药品代码变化响应函数
procedure TSell.Edit3Change(Sender: TObject);
begin
AdoTable2.locate('药品代码',Edit3.text,[locaseinsensitive,lopartialkey]);
edit5.text:=adotable2.fieldValues['销售单价'];
edit2.text:=adotable2.fieldValues['药品名称'];
end;
//查询按钮响应函数
procedure TSell.Button4Click(Sender: TObject);
begin
if Edit7.Text<>'' then
begin
if
Adotable1.Locate(ComboBox1.Items[ComboBox1.itemIndex],Edit7.Text,[loCaseinsensitive,lopartialkey])
//如果能查到符合此记录的记录
then
begin
//通过销售窗体详细显示
Edit1.Text:=DateToStr(Adotable1.FieldValues['销售日期']);
Edit2.Text:=Adotable1.FieldValues['药品名称'];
Edit3.Text:=Adotable1.FieldValues['药品代码'];
Edit4.Text:=IntToStr(adotable1.FieldValues['销售数量']);
Edit5.Text:=FloatToStr(Adotable1.FieldValues['销售单价']);
Edit6.Text:=FloatToStr(Adotable1.FieldValues['销售金额']);
end
else //对应着没查到
Showmessage('对不起,查不到您输入的药品信息!') ;
end
else //对应着查询信息输入为空
begin
ShowMessage('请输入要查询的药品名称');
Edit7.SetFocus; //然后将光标移到Edit7上
end
end;
end.
不知道哪里出错了,一运行就出现Project ypjxc.exe raised exception class EAccessViolation with message 'Access violation at address 00404660 in module 'ypjxc
.exe'. Read of address 0000001A'. Process stopped.Use Step or Run to continue. 这样的错误,麻烦大家帮我看看哪里出错了
PS:想找一个delphi强一点的人当下临时老师,很多东西书上看不太懂,不会耽误您太多时间,偶尔请教些问题,都是很基本的,愿意的请加我Q:624376959 谢谢啦