unit Unit11_ruku;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus,unit_kulei, ComCtrls, Grids, DBGrids, StdCtrls, Buttons ,unit_yuanlei, unit_churulei,unit_wulei,unit_cunlei;type
  TForm11 = class(TForm)
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    ComboBox1: TComboBox;
    Label1: TLabel;
    Edit1: TEdit;
    ComboBox2: TComboBox;
    Label2: TLabel;
    ComboBox3: TComboBox;
    Label3: TLabel;
    Label4: TLabel;
    ComboBox4: TComboBox;
    Label5: TLabel;
    Label6: TLabel;
    DateTimePicker1: TDateTimePicker;
    Label7: TLabel;
    ComboBox5: TComboBox;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    DBGrid1: TDBGrid;
    PopupMenu1: TPopupMenu;
    Label8: TLabel;
    N1: TMenuItem;
    UpDown1: TUpDown;
    procedure BitBtn4Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
  churu:tchuru;
  wupin:twupin;
  ku:tku;
  caozuo:tcaozuo;
  cun:tcun;
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form11: TForm11;implementationuses Unit2_shuju;{$R *.dfm}procedure TForm11.BitBtn4Click(Sender: TObject);
begin
close;
end;procedure TForm11.N1Click(Sender: TObject);
begin
   datamodule2.ADOQuery6.close;
   datamodule2.ADOQuery6.sql.Clear;
   datamodule2.ADOQuery6.Parameters.Clear;
   datamodule2.ADOQuery6.sql.Add('select * from churuku where 出入库单编号 like ''I%''');
   datamodule2.ADOQuery6.open;
end;procedure TForm11.BitBtn1Click(Sender: TObject);
var
str:string;
pum:integer;
begin
churu:=tchuru.create;
if combobox1.Text='' then
begin
application.MessageBox('入库单编号不能为空','警告',mb_ok);
end
else
   if not churu.checkchuid(combobox1.Text) then
      begin
      if copy(combobox1.Text,1,1)<>'I' then
         begin
         application.MessageBox('入库单编号要以i开头','警告',mb_ok);
         exit;
         end;
      if not wupin.checkwuname(combobox3.Text) then
         begin
         application.MessageBox('不存在该物品编码','警告',mb_ok);
         exit;
         end;
      if not caozuo.checkyuanid(combobox2.Text) then
         begin
         application.MessageBox('不存在该操作员编号','警告',mb_ok);
         exit;
         end;
      if not ku.checkkuid(combobox5.Text) then
         begin
         application.MessageBox('不存在该库位号','警告',mb_ok);
         exit;
         end;      str:='insert into churuku(出入库单编号,操作员编号,入库品编码,入库品数量,物品单位,入库时间,入库计划库位'+')values('''+combobox1.text+''','''+combobox2.Text+''''
      +','''+combobox3.Text+''','''+edit1.Text+''','''+combobox4.Text+''','''+datetostr(datetimepicker1.Date)+''','''+combobox5.Text+''')';
      churu.insertchuru(str);
      with datamodule2.ADOQuery7 do
          begin
          close;
          sql.Clear;
          sql.Add('select * from kucun where 物品编码='''+combobox3.text+''' and 库位代号='''+combobox5.text+'''');
          open;
          if recordcount=0 then
             begin
             close;
             sql.Clear;
             sql.Add('insert into kucun(物品编码,库存数量,物品单位,库位代号)values('''+combobox3.text+''','''+edit1.Text+''','''+combobox4.text+''','''+combobox5.text+''') ');
             execsql;
             end
             else
             begin
             pum:=strtoint(edit1.Text)+STRTOINT(cun.getwuliang('库存数量'));
             close;
             sql.Clear;
             sql.Add('update kucun set 库存数量='''+inttostr(pum)+'''where 物品编码='''+combobox3.text+''' and 库位代号='''+combobox5.text+''' ');
             execsql;
             end;
          end;
      application.MessageBox('入库单信息添加成功','提示',mb_ok);
      edit1.Text:='';
      combobox5.Text:='';
      combobox4.Text:='';
      combobox1.Text:='';
      combobox2.Text:='';
      combobox3.Text:='';      end
      else
      application.MessageBox('入库单编号已经存在','警告',mb_ok);churu.Free;
end;
问题是:出现错误!with message'''is not a valid integer value'通过断点查问题 发现问题在pum:=strtoint(edit1.Text)+STRTOINT(cun.getwuliang('库存数量'));
这个语句上。导致sql.Add('update kucun set 库存数量='''+inttostr(pum)+'''where 物品编码='''+combobox3.text+''' and 库位代号='''+combobox5.text+''' ');无法执行。
cun.getwuliang('库存数量')这个类 具体是cun.getwuliang(name:string):string;库存数量的数据类型是INT,这个程序是入库单录入程序,通过录入信息检验库存信息是否存在
如果不存在,把某些信息插入库存信息当中,存在的话,把这次的物品数量加上库存数量一起,然后修改库存数量,入库表与库存表是2个不同的表,我已经把能想到的都说了
希望高手帮我看下问题出在哪 这个问题使得我做的一个系统好多类似地方不能执行结果 急求!还有一个问题:本人自学的DELPHI,一切都靠书本或者上论坛请教,无人面授经验,只希望早点达到一个初级程序员的入门条件,好进个小公司积累经验。
问题可能有点初级,请高手帮帮新人。
创建类的实例比方说churu:=tchuru.create;与类的释放churu.Free;可是在程序当中,我发现根本不需要创建与释放也可以用 上面的程序当中 几个类我都没创建与释放 一样可以用
我想知道区别在哪 是不是只要放在private
                               churu:tchuru;
                               wupin:twupin;
                               ku:tku;
                               caozuo:tcaozuo;
                               cun:tcun;就可以了呢?
try
....
except
.... 
end中间2段代码代表什么?是不是尝试去做。。 否者。。的意思 最好有代码具体解释下 :)

解决方案 »

  1.   

    strtoint(edit1.Text)建议换成StrToIntDef(edit1.text,0),如果转换失败就会返回0,当然也可以设置成其他数值如果不创建类的实例,可以直接使用类级别的函数(class procedure(function)),而类的其他成员及函数无法访问
    不释放,delphi会自动回收垃圾,不过好的编程习惯,建议还是写规矩些
      

  2.   

    呵呵 又是你 上回回答问题的就是你 这回又是你 谢谢你了 我再等等 看还有没有具体点的strtoint(edit1.Text)建议换成StrToIntDef(edit1.text,0)这个返回0值 也不能完成预期的效果啊 还是不能根本解决问题 如果你说的可以的话!
      

  3.   

    pum:=strtoint(edit1.Text)+STRTOINT(cun.getwuliang('库存数量'));
    改成:
    pum:=StrToIntDef(edit1.Text, 0)+StrToIntDef(cun.getwuliang('库存数量'), 0);
      

  4.   

    pum:=strtoint(edit1.Text)+STRTOINT(cun.getwuliang('库存数量')); 
    首先你要保证edit1.text可以转换成int,再有保证cun.getwuliang('库存数量')的返回值可以转换成int,你现在的问题就在这,是转换错误,edit1.text和cun.getwuliang('库存数量')中,肯定有不符合转换规则的,你查到它,然后做相应处理就可以了
      

  5.   

    pum:=StrToIntDef(edit1.Text, 0)+StrToIntDef(cun.getwuliang('库存数量'), 0);咱打个比方说 就是当它转换失败了 就当出现错误!with message'''is not a valid integer value'通过断点查问题 这个问题解决了
    下面的修改语句sql.Add('update kucun set 库存数量='''+inttostr(pum)+'''where 物品编码='''+combobox3.text+''' and 库位代号='''+combobox5.text+''' ');也能执行了 问题是都返回0 PUM不也是0了吗 就算一个返回的0 那要修改的数据也不对了啊
      

  6.   

    1、类与类的实例是两个概念,必须要用类的实例,当然要创建和释放。
       不创建也能用?别开玩笑了,难道我没睡醒?
    2、
    try
    ....
    except
    ....
    end
    用于例外(异常)处理,通常情况下很有必要
    3、
    Edit1的内容的合法性没有处理,应该处理onkeydown事件以限制只能输入数字(还有#8#9#13)
    同时要判断trim(edit1.text)是否为空,若为空也不允许
      

  7.   

    谢谢bdmn的解答 如果问题真象你说的那样 只出在转换规则上 那么改就可以了 我就怕出错误真返回0 那不就更完了嘛 呵呵 谢谢 我在再线等等 其他人的回答 上次那个低级问题就你帮我解决的 还记得吗
      

  8.   


    你还没明白我得意思,pum是你查询的一个条件,所以你要保证他有正确的值,这个就来自你得代码pum:=strtoint(edit1.Text)+STRTOINT(cun.getwuliang('库存数量')); 
    所以要保证edit1.text和cun.getwuliang('库存数量')两个值都可以正确转换,才可得到正确的pum,明白了吗
      

  9.   

    而且你得sql语句好像也有问题
    库存数量='''+inttostr(pum)中库存数量=后面难得是双引号吗,不是整型的吗,那样就不用引号了
    where前没有空格
      

  10.   

    Edit1的内容的合法性没有处理,应该处理onkeydown事件以限制只能输入数字(还有#8#9#13)什么意思
    特别是#8#9#13 我根本就没用过 不知道怎么用:(
      

  11.   

    用下面的函数,初始化时把edit的onchange事件指向ed_NumChange,当edit内容变化时,就会检查里面的内容是否符合规范
    procedure ed_NumChange(Sender: TObject);
    var
      code:integer;
      num:integer;
    begin
      Val(TEdit(Sender).Text, num, code);
      if Trim(TEdit(Sender).Text) = '' then
        TEdit(Sender).Text := '0'
      else if code > 0 then
      begin
        Application.MessageBox(PChar('数值格式错误!'),PChar('信息提示'),MB_OK or MB_ICONINFORMATION);
        if Trim(TEdit(Sender).Text) = '' then
          TEdit(Sender).Text := '0'
        else
          TEdit(Sender).Text := LeftStr(TEdit(Sender).Text,code-1);
        Exit;
      end;
    end;
      

  12.   


    #8是退格,敲错了的话,应允许退格
    #9是Tab键
    #13是回车键
      

  13.   

    showmessage(sql.text)
    看一下SQL 语句是否正确.