一个药品的相关的查询,一个是药品分类表,有TYPE_id,type_nm,TYPE_id代表分类索引号,共6位字符。第一位代表中西药,1为中药,0为西药,后两位为大科目,比如内、外科,最后三位为小的类别,比如感冒,发烧!药品表有ID,NM,功效等,药品ID前六位是类别ID,后面才是编号!现目的,是有几个按钮BUTTON1至BUTTONn,如:当我点中药时,BUTTON1的CAPTION是内科,点了BUTTON1时,就是查询到的第一个数据‘感冒’,点‘感冒’后就把药品表中的相关的药名取出来放在BUTTON1上,当点击后把药品相关列在各BUTTON上!我写的代码出错了,调试不出,请大家试着写一写代码给我,不胜感激!耗子!

解决方案 »

  1.   

    我愿意帮助您,请给我您的程序,数据库和要求!您上面写的我还是不太明白![email protected]
      

  2.   

    你去找coolslob帮你,他可是做了一个硕大的一个医院系统,好像他们公司还接了不少客户?
    看看去?
      

  3.   

    procedure TForm1.SpeedButton1Click(Sender: TObject);
    var
    str:string;
    i:integer;
    begin
    str:=SPeedButton1.Caption;if (length(lastid)<6) then begin
    with Query2 do begin
       with SQL do begin
         query1.Close ;
         Clear;
         Add('Select * from type Where type_nm='+#39+str+#39);
       end;
       Open;
    end;
    secondclass:=str;
    str:=query2.FieldValues['type_id'];
    str:=str+'%';
    Query2.Close;
    with Query1 do begin
            with SQL do begin
            Clear;
            Add('Select * from type Where type_id like '+#39+str+#39);
            end;
            Open;
    end;
    lastid:=query1.FieldValues['type_id'];
    PageIndex:=1;
    RecordSum:=0;
    i:=query1.RecordCount;
    clearSpeedButton();
    //lastId:=str;
    //ShowMessage(lastid);
    thirdclass:='';
    forthclass:='';
    typelist(i,PageIndex);
    end
    else if (length(lastid)=6) then begin
     str:=SPeedButton1.Caption;
     with Query2 do begin
       with SQL do begin
         query1.Close;
         Clear;
         Add('Select * from type Where type_nm='+#39+str+#39);
       end;
       Open;
    end;
    secondclass:=str;
    str:=query2.FieldValues['type_id'];
    str:=lastID+'_%';
    Query2.Close;
    with Query1 do begin
            with SQL do begin
            Clear;
            Add('Select * from medicine Where medicine_id like '+#39+str+#39);
            end;
            Open;
    end;
    lastid:=query1.FieldValues['medicine_id'];
    PageIndex:=1;
    RecordSum:=0;
    i:=query1.RecordCount;
    clearSpeedButton();
    //lastId:=str;
    ShowMessage(lastid);
    thirdclass:='';
    forthclass:='';
    typelist(i,PageIndex);
    end;
    end;
      

  4.   

    上边ELSE后的就不能正常运行了!
      

  5.   

    procedure TForm1.SpeedButton1Click(Sender: TObject);
    var
    str:string;
    i:integer;
    begin
    str:=SPeedButton1.Caption;if (length(lastid)<6) then begin
    with Query2 do begin
       with SQL do begin
         query1.Close ;
         Clear;
         Add('Select * from type Where type_nm='+#39+str+#39);
       end;
       Open;
    end;
    secondclass:=str;
    str:=query2.FieldValues['type_id'];
    str:=str+'%';
    Query2.Close;
    with Query1 do begin
            with SQL do begin
            Clear;
            Add('Select * from type Where type_id like '+#39+str+#39);
            end;
            Open;
    end;
    lastid:=query1.FieldValues['type_id'];
    PageIndex:=1;
    RecordSum:=0;
    i:=query1.RecordCount;
    clearSpeedButton();
    //lastId:=str;
    //ShowMessage(lastid);
    thirdclass:='';
    forthclass:='';
    typelist(i,PageIndex);
    end
    else if (length(lastid)=6) then begin
     str:=SPeedButton1.Caption;
     with Query2 do begin
       with SQL do begin
         query1.Close;
         Clear;
         Add('Select * from type Where type_nm='+#39+str+#39);
       end;
       Open;
    end;
    secondclass:=str;
    str:=query2.FieldValues['type_id'];
    str:=lastID+'_%';
    Query2.Close;
    with Query1 do begin
            with SQL do begin
            Clear;
            Add('Select * from medicine Where medicine_id like '+#39+str+#39);
            end;
            Open;
    end;
    lastid:=query1.FieldValues['medicine_id'];
    PageIndex:=1;
    RecordSum:=0;
    i:=query1.RecordCount;
    clearSpeedButton();
    //lastId:=str;
    ShowMessage(lastid);
    thirdclass:='';
    forthclass:='';
    typelist(i,PageIndex);
    end;
    end;
    把你的详细请矿说一下,没有看明白,太乱了
      

  6.   

    if (length(lastid)<6) then begin
    with Query2 do begin
       with SQL do begin
         query1.Close ;
         Clear;
         Add('Select * from type Where type_nm='+#39+str+#39);
       end;
       Open;
    end;
    secondclass:=str;
    str:=query2.FieldValues['type_id'];
    str:=str+'%';
    Query2.Close;
    with Query1 do begin
            with SQL do begin
            Clear;
            Add('Select * from type Where type_id like '+#39+str+#39);
            end;
            Open;
    end;
    lastid:=query1.FieldValues['type_id'];
    PageIndex:=1;
    RecordSum:=0;
    i:=query1.RecordCount;
    clearSpeedButton();
    thirdclass:='';
    forthclass:='';
    typelist(i,PageIndex);
    这是为了检测当后面要列的还是药品类时所做,可以实现
    if (length(lastid)=6) then begin
     str:=SPeedButton1.Caption;
     with Query2 do begin
       with SQL do begin
         query1.Close;
         Clear;
         Add('Select * from type Where type_nm='+#39+str+#39);
       end;
       Open;
    end;
    secondclass:=str;
    str:=query2.FieldValues['type_id'];
    str:=lastID+'_%';
    Query2.Close;
    with Query1 do begin
            with SQL do begin
            Clear;
            Add('Select * from medicine Where medicine_id like '+#39+str+#39);
            end;
            Open;
    end;
    这里边的查询通不过!
      

  7.   


    'Select * from medicine Where medicine_id like '+ QuotedStr(str)
      

  8.   

    不是STR的问题吧,因为前一段可以执行的!
      

  9.   

    with Query2 do begin
       with SQL do begin
    With语句不可以嵌套!
    With statements
    Topic groups See also
    A with statement is a shorthand for referencing the fields of a record or the fields, properties, and methods of an object. The syntax of a with statement iswith obj do statementorwith obj1, ..., objn do statementwhere obj is a variable reference denoting an object or record, and statement is any simple or structured statement. Within statement, you can refer to fields, properties, and methods of obj using their identifiers alone梬ithout qualifiers.
    For example, given the declarationstype TDate = record  Day: Integer;
      Month: Integer;
      Year: Integer;
    end;var OrderDate: TDate;you could write the following with statement.with OrderDate do  if Month = 12 then
      begin
        Month := 1;
        Year := Year + 1;
      end
      else
        Month := Month + 1;This is equivalent toif OrderDate.Month = 12 thenbegin
      OrderDate.Month := 1;
      OrderDate.Year := OrderDate.Year + 1;
    end
    else
      OrderDate.Month := OrderDate.Month + 1;If the interpretation of obj involves indexing arrays or dereferencing pointers, these actions are performed once, before statement is executed. This makes with statements efficient as well as concise. It also means that assignments to a variable within statement cannot affect the interpretation of obj during the current execution of the with statement.
    Each variable reference or method name in a with statement is interpreted, if possible, as a member of the specified object or record. If there is another variable or method of the same name that you want to access from the with statement, you need to prepend it with a qualifier, as in the following example.with OrderDate do  begin
        Year := Unit1.Year
        ...
      end;When multiple objects or records appear after with, the entire statement is treated like a series of nested with statements. Thuswith obj1, obj2, ..., objn do statementis equivalent towith obj1 do  with obj2 do
         ... 
         with objn do
           statementIn this case, each variable reference or method name in statement is interpreted, if possible, as a member of objn; otherwise it is interpreted, if possible, as a member of objn?; and so forth. The same rule applies to interpreting the objs themselves, so that, for instance, if objn is a member of both obj1 and obj2, it is interpreted as obj2.objn.