如何检查Tlist中是否存在字符串,无论其是低位还是大写

Mar*_*nel 1 delphi delphi-xe7

我创建了一个函数来检查Tlist中是否存在字符串,这是我的代码

function FindDtataLIST(namestring: String): BOOLEAN;
var
  I: Integer;
begin
  Result := False;
  for I := 0 to Listofdata.Count - 1 do
  begin
    if TData(Listofdata.Items[I]).Name = namestring then
    begin
      Result := True;
      Exit;
    end;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

但是我坚持一些陷阱,如果我的listofdata字符串以大写字母为例:'MaRtiN' 并且名字字符串等于小写字母作为例子:martin结果没有返回True我想检查

if FindDtataLIST(namestring) = True 每当nametring以大写字母或小字母存在时

Gab*_*elF 6

如果您只想检查两个字符串是否相等,可以使用AnsiSameText:

function FindDtataLIST(namestring: String): BOOLEAN;
var
  I: Integer;
begin
  Result := False;
  for I := 0 to Listofdata.Count - 1 do
  begin
    if AnsiSameText(TData(Listofdata.Items[I]).Name, namestring) then
    begin
      Result := True;
      Exit;
    end;
  end;
end;
Run Code Online (Sandbox Code Playgroud)