请给出tstrings类中的IndexOfName方法程序实例。IndexOfName此方法是什么意思??

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      tmplist:TStringList;
    begin
      tmplist:=TStringList.Create ;
      tmplist.Add('a1=b1');
      tmplist.Add('a2=b2');
      showmessage(inttostr(tmplist.IndexOfName('a1')));
      showmessage(inttostr(tmplist.IndexOfName('a2')));
      tmplist.Free ;
      //此方法多用于操作INI文件等;
    end;
      

  2.   

    看帮助啊!The following example updates the strings in a list box given the strings contained in another list box. If a string in the source list box has the form Name=Value and the destination list box contains a string with the same Name part, the Value part in the destination list box will be replaced by the source抯 value.  procedure MergeStrings(Dest, Source: TStrings);var
      I, DI: Integer;
      begin
      for I := 0 to Source.Count - 1 do
      begin
        if Pos ('=', Source[I]) > 1 then
        begin
          DI := Dest.IndexOfName(Source.Names[I]);
          if DI > -1 then Dest[DI] := Source[I];
        end;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      MergeStrings(ListBox1.Items,ListBox2.Items);
    end;
      

  3.   

    看VCLfunction TStrings.IndexOfName(const Name: string): Integer;
    var
      P: Integer;
      S: string;
    begin
      for Result := 0 to GetCount - 1 do
      begin
        S := Get(Result);
        P := AnsiPos('=', S);
        if (P <> 0) and (CompareStrings(Copy(S, 1, P - 1), Name) = 0) then Exit;
      end;
      Result := -1;
    end;