通过edit1.text:=ValueListEditor1.Values[ValueListEditor1.Keys[n]] 可以把第n行的value的信息显示在edit1上面我现在要想通过values的值来获得行号n 不知各位有何高见PS:edit1.text:=ValueListEditor1.Keys[ValueListEditor1.Values['字符串']] 没有用
错误信息:Incompatible types: 'Integer' and 'String'edit1.text:=inttostr(ValueListEditor1.Keys[ValueListEditor1.Values['字符串']])以及加trim都没有用 报的一样的错误请各位提供点有效的意见,不胜感激!

解决方案 »

  1.   

    edit1.text:=ValueListEditor1.Values[ValueListEditor1.Keys[n]]); 
    没错啊~~
    你的n是什么类型,是不是integer?
      

  2.   

    第一句代码是正确的。所谓的Keys、Values都是对Strings属性的封装,而Strings正是TStrings类型,内部采用的是”Name=Value“的格式。如果想获取某个Key,可以用Keys[n: Integer],如果想获取某个Key对应的Value,可以用Values[key: string];如果想根据某个Value来获取对应的Key/行号,只能采用遍历的方式,如:
    [Code=Delphi]
    function FindKeyIndex(strings: TStrings; const value: string): Integer;
    var
      i: Integer;
    begin
      Result := -1;
      for i := 0 to strings.Count - 1 do
      begin
        if AnsiSameText(strings.ValueFromIndex[i], value) then
        begin
          Result := i;
          Break;
        end;
      end;
    end;
    [Code]
      

  3.   

    第一句代码是正确的。 所谓的Keys、Values都是对Strings属性的封装,而Strings正是TStrings类型,内部采用的是”Name=Value“的格式。 如果想获取某个Key,可以用Keys[n: Integer],如果想获取某个Key对应的Value,可以用Values[key: string]; 如果想根据某个Value来获取对应的Key/行号,只能采用遍历的方式,如: 
     
    function FindKeyIndex(strings: TStrings; const value: string): Integer; 
    var 
      i: Integer; 
    begin 
      Result := -1; 
      for i := 0 to strings.Count - 1 do 
      begin 
        if AnsiSameText(strings.ValueFromIndex[i], value) then 
        begin 
          Result := i; 
          Break; 
        end; 
      end; 
    end; 
      

  4.   

     
    function FindKeyIndex(strings: TStrings; const value: string): Integer; 
    var 
      i: Integer; 
    begin 
      Result := -1; 
      for i := 0 to strings.Count - 1 do 
      begin 
        if AnsiSameText(strings.ValueFromIndex[i], value) then 
        begin 
          Result := i; 
          Break; 
        end; 
      end; 
    end; 
      

  5.   


    function FindKeyIndex(strings: TStrings; const value: string): Integer; 
    var
      i: Integer;
    begin
      Result := -1;
      for i := 0 to strings.Count - 1 do
      begin
        if AnsiSameText(strings.ValueFromIndex[i], value) then
        begin
          Result := i;
          Break;
        end;
      end;
    end;
      

  6.   

    index := FindKeyIndex(ValueListEditor1.Strings, 'abc');