if StringList.IndexOf(S) < 0 then StringList.Add(S);
Call IndexOf to obtain the position of the first occurrence of the string S. IndexOf returns the 0-based index of the string. Thus, if S matches the first string in the list, IndexOf returns 0, if S is the second string, IndexOf returns 1, and so on. If the string is not in the string list, IndexOf returns -1.
----------------------------------------------
function IndexOfArray(const Arr: array of String; const S: String): Integer; var I: Integer; begin Result := -1; for I := 0 to Length(Arr) - 1 do // 如果你要求大小写不敏感,将CompareStr换成CompareText即可 if CompareStr(Arr[I], S) = 0 then begin Result := I; Exit; end; end;
if IndexOfArray(StrArray, Str) < 0 then ......
----------------------------------------------