在FORM1中,用QUERY和DATESOURCE控件,把查询的结果放入DBGRID中,怎么样才能在查询结果中定位查找某条记录?忘各位大哥帮忙指点,谢谢,在线等!

解决方案 »

  1.   

    定位到列名name=Jack的记录
    QUERY1.Locate('Name','Jack',[]);
      

  2.   

    QUERY1.Locate('KeyField','Value',[]);
    其中VALUE为变量怎么办?
      

  3.   

    var
     value: string;
    begin
    value := 'Jack';
    QUERY1.Locate('KeyField',value,[]);
      

  4.   

    上面的大哥,我试了,不行啊,那个QUERY1.Locate('KeyField',value,[]);中VALUE一定要是常量才行啊,换成变量就跳到第一行去
      

  5.   

    QUERY1.Locate('KeyField',value,[]);这个方法中的VALUE只能是常量,它的格式是QUERY1.Locate(CONST KeyFiel:STRING',CONST value:STRING,[]);
    不能给变量,还有别的方法可以搞定吗?
      

  6.   

    呵呵!谁说不能给变量~~~Const是为了传进去的变量不被函数修改!
    你加个TEDIT试一下就知道了
    QUERY1.Locate('KeyField',Edit1.Text,[]);
      

  7.   

    EDIT1.TEXT:='P25698'
    QUERY1.Locate('KeyField',Edit1.Text,[]);
    这样会跳到第一行去
    EDIT1.TEXT:=FORM2.EDIT1.TEXT;
    QUERY1.Locate('KeyField',Edit1.Text,[]);
    这样会报错是怎么回事啊??
      

  8.   

    procedure TForm7.N3Click(Sender: TObject);
    var
     value: string;
    beginForm_in_storage_detail.Edit2.Text:= DBGrid_regimentation.DataSource.DataSet.Fields[1].AsString ;
     value:=Form_in_storage_detail.Edit2.Text; if Form7=nil then
         Form7:=TForm7.Create(nil);
         if Form7.Query_search_goods.Active then
         Form7.Query_search_goods.close ;
         Form7.Query_search_goods.ParamByName('goods_id').AsString:=form_in_storage_detail.EDIT2.Text+'%';
          Form7.Query_search_goods.Open;        form_in_storage_detail.edit2.Text:=form7.DBGrid_regimentation.Fields[0].AsString;
            form_in_storage_detail.edit3.Text:=form7.DBGrid_regimentation.Fields[2].AsString;
             form_in_storage_detail.edit4.Text:=form7.DBGrid_regimentation.Fields[4].AsString;
             form_in_storage_detail.edit5.Text:=form7.DBGrid_regimentation.Fields[5].AsString;
              form_in_storage_detail.edit6.Text:=form7.DBGrid_regimentation.Fields[6].AsString;        if trim(form_in_storage_detail.edit2.text)='01' then
               begin              form_in_storage_detail.EDIT2.Text:='昌力'
               end;
                if trim(form_in_storage_detail.edit2.text)='02' then
               begin              form_in_storage_detail.EDIT2.Text:='昌力三分厂'
               end;
                 if trim(form_in_storage_detail.edit2.text)='04' then
               begin              form_in_storage_detail.EDIT2.Text:='长力'
               end;
                 if trim(form_in_storage_detail.edit2.text)='03' then
               begin              form_in_storage_detail.EDIT2.Text:='昌力分厂'
               end;
                 if trim(form_in_storage_detail.edit2.text)='05' then
               begin              form_in_storage_detail.EDIT2.Text:='昌力定做'
               end;
    form_in_storage_detail.DBGD_in_storage_detail.DataSource.DataSet.Append;form_in_storage_detail.DBGD_in_storage_detail.Fields[0].AsString:=form_in_storage_detail.edit2.Text;
    form_in_storage_detail.DBGD_in_storage_detail.Fields[1].AsString:=form_in_storage_detail.edit4.Text;
    form_in_storage_detail.DBGD_in_storage_detail.Fields[2].AsString:=form_in_storage_detail.edit5.Text;
    form_in_storage_detail.DBGD_in_storage_detail.Fields[3].AsString:=form_in_storage_detail.edit6.Text;
    if  Query_search_goods.Active then
        Query_search_goods.Close;
         Query_search_goods.ParamByName('goods_subject').AsString:=PNodeData(treeview_regimentation.Selected.Data)^.node_id;
         Query_search_goods.ParamByName('goods_category').AsString:='%';
         Query_search_goods.ParamByName('goods_project').AsString:='%';
         Query_search_goods.ParamByName('goods_name').AsString:=trim(ed_name.Text)+'%';
         Query_search_goods.ParamByName('goods_specification').AsString:=trim(ed_guige.text)+'%';
         Query_search_goods.ParamByName('goods_place').AsString:=trim(Ed_place.Text)+'%';
         Query_search_goods.ParamByName('goods_id').AsString:=edit1.Text+'%';     Query_search_goods.Prepare;     Query_search_goods.Open;
         Query_search_goods.Locate('GOODS_ID','value',[]);end;
      

  9.   

    Query_search_goods.Locate('GOODS_ID','value',[]);
    你写'value'当然不行啦!你想根据那个字段去查!晕,原代码更加恐怖,乱!!我说兄台,你不用会用
    with...do语句吗?