我要所选择的combobox中所显示的商品名称,以及它对应的价格一起添加到memo中,并将所选择的商品的价格求总和,赋值给EDIT,(注意要判断它是否已经添加过)。我用下面的代码实现,能将所选择的商品及价格加到MEMO中但是没有实现计算总价格和是否添加过的判定,假如我不要那段查询只是将combobox中的商品名称添加MEMO中又能实现是否添加过的判定!请各位帮忙解决!这个问题已经捆扰我很长时间了
procedure TForm4.ComboBox1Click(Sender: TObject);
var s:integer;
begin
if pos(combobox1.text+s+';' , memo1.text)=0 then
  begin
  query1.close;
  query1.sql.clear;
  query1.sql.add('select age from rskb where name=:num');
  query1.parambyname('num').asstring:=combobox1.text;
  query1.prepare;
  query1.open;
  s:=query1.fieldbyname('prich').asinteger;
  memo1.text := memo1.text + combobox1.text +s+ ';' ; 
  end
else
  Application.MessageBox('数据已经存在!','信息提示!',MB_Iconinformation);combobox中的值是通过下面的代码获得:
procedure TForm4.FormCreate(Sender: TObject);
var
  s:string;
  I:Integer;
begin
  with Table1 do
  for I:=0 to RecordCount-1 do
  begin
    s:=Table1['Name'];
    ComboBox1.Items.Add(s);
    Table1.Next;
  end;
end;
请各位帮忙看看我应该怎么做啊!!谢谢了!

解决方案 »

  1.   

    价格:strtofloat(eidt1.text)+query1.fieldbyname('prich').asinteger;
    是否添加过的判定:可以在每次添加后在ComboBox1中删除,还有用一个tListBox1来记住它,在每次添加前判断
      

  2.   

    加一个ListBox1,ListBox1.Visible
    在procedure TForm4.FormCreate(Sender: TObject);中加edit1.text:='0';procedure TForm4.ComboBox1Click(Sender: TObject);
    var s:integer;
        B:bool;//
    begin
    if pos(combobox1.text+s+';' , memo1.text)=0 then
      begin
      query1.close;
      query1.sql.clear;
      query1.sql.add('select age from rskb where name=:num');
      query1.parambyname('num').asstring:=combobox1.text;
      query1.prepare;
      query1.open;
       B:=false;
      for i:=0 to ListBox1.Items.Count-1 do
       begin
         if combobox1.text=ListBox1.Items[i] then
            B:=true;
       end;
      if B=true then
       begin
         Application.MessageBox('已经存在!','信息提   示!',MB_Iconinformation);
        exit;   end;
      ListBox1.Items.Add(combobox1.text);
      
      s:=query1.fieldbyname('prich').asinteger;
      edit1.text:=floattostr((strtofloat(edit1.text)+s));
      memo1.text := memo1.text + combobox1.text +s+ ';' ; 
      end
    else
      Application.MessageBox('数据已经存在!','信息提示!',MB_Iconinformation);
    累死了,自己测试一下吧
      

  3.   

    你的程序好像是用来在销售终端用的..
    但偶有点看不明白..你的意思..
    [email protected]
    有空交流吧..
      

  4.   

    可以将商品名称和商品代号(唯一)和商品价格一起添加到ComboBox中,中间用空格和特殊符号间隔比如@#
    ComboBox.Items[0]:='XXX牌卫生巾                 @5.5  #101';
    中间用空格是为了不让价格显示出来,当然你要将ComboBox.Style:=csDropDownList;
    然后再写两个函数分别读取ComboBox.Items的名称(get_mc)和代号(get_dh)和价格(get_jg);
    当往Memo中添加的时候,将已经添加的商品代号用数组(Arr_s)存放,通过数组来判断是否已经添加某个商品
    for i:=0 to length(arr_s)-1 do
    begin
      if get_dh(ComboBox.Items[ComboBox.Itemindex]) = arr_s[i] then
        begin
          Application.MessageBox('该商品已经添加','提示',64);
          exit;
        end;
    end;