with table1 do
  begin
     setkey;
     fieldbyname('name').AsString:=edit1.Text;
     if gotokey then
       statusbar1.SimpleText:='找到了关于'+edit1.text+'的记录'
     else
       messagedlg('呵呵,没有找到这个国家!',mtwarning,[mbok],0);
  end;请教: 1.setkey 的用法?
      2.还有第四行的fieldbyname('name').AsString 是什么意思?
      3.还有gotokey的用法?
  向大家请教,我刚开始学,请原谅我的无知!!

解决方案 »

  1.   

    Enables setting of keys and ranges for a dataset prior to a search.Delphi syntax:procedure SetKey;DescriptionCall SetKey to put the dataset into dsSetKey state and clear the current contents of the key buffer. The FieldByName method can then be used to supply a new set of search values prior to conducting a search.Note: To modify an existing key or range, call EditKey.SetKey是设置查找字段的查找内容,
    你上面的语句的意思是查找字段name内容为edit1.text的记录
    gotokey是以SETKEY后的fieldbyname设置内容作为查找条件,返回记录,
    Use GotoKey to move to a record specified by key values assigned with previous calls to SetKey or EditKey and actual search values indicated in the Fields property.If GotoKey finds a matching record, it positions the cursor on the record and returns true. Otherwise the current cursor position remains unchanged, and GotoKey returns false.
    上面的意思就是说GOTOKEY查找符合的条件后,如果有记录就返回true,并指向记录,如果没有就返回FALSE
      

  2.   

    1,setkey是开始设置查找条件
    2,filedbyname("name").asstring是设置需要查找的字段以及符合条件的内容
    3,gotokey就相当于执行查找条件了,返回是否存在符合条件的记录,返回值是一个boolean型的,如有的话,并指向记录集
      

  3.   

    不用TTABLE,用TQUERY真接写查询语句,然后判断数据集是否为空。
      

  4.   

    1,不太清楚,不敢胡说!
    2,将字段值转换为字符型,即string;
    3,不太清楚,不敢胡说!不过你可以F1
      

  5.   

    funboy88(司令) :谢谢你的详细解答!如果我使用gotokey这种方法进行查询,是否必须先使用setkey进行设置 ??