E2267'ExtractTokens'的先前声明未标记'overload'指令

时间:2017-09-18 08:07:58

标签: delphi

我不明白如何解决这个错误! 这是错误代码的一部分。 我无法弄清楚在哪里使用过载。

 function ExtractTokens(const line: AnsiString; const sep: AnsiChar; autoUnquote: boolean = true): TStringArray;
var
  lineIndex: integer;

  function NextChar(out ch: char): boolean;
  begin
    if lineIndex <= length(line) then
    begin
      result := true;
      ch := line[lineIndex];
      inc(lineIndex);
    end
    else
      result := false;
  end;
  function PeekFor(const ch: AnsiChar): boolean;
  begin
    result := false;
    if lineIndex <= length(line) then
    begin
      if line[lineIndex] = ch then
      begin
        inc(lineIndex);
        result := true;
      end;
    end;
  end;
  function UnquoteIfNecessary(const tok: string; quoteChar: char): string;
  var
    pch: PChar;
  begin
    if autoUnquote then
    begin
      pch := pchar(tok);
      result := AnsiExtractQuotedStr(pch, quoteChar);
    end
    else
      result := tok;
  end;
var
  token: string;
  stok: string;
  ch: char;
  lastChar: char;
  strSep: char;
  inString: boolean;

  function IsSep(aChar: char): boolean;
  begin
    result := (aChar = sep) or ((sep = #0) and (ord(aChar) < 33));
  end;

  procedure AddToken(var tokens: TStringArray; const tkn: string; addEmpty: boolean = true);
  var
    s: string;
  begin
    s := trim(tkn);
    if addEmpty or (s <> '') then
    begin
      SetLength(tokens, length(tokens) + 1);
      tokens[high(tokens)] := s;
    end;
    token := '';
  end;
begin
  result := nil;
  token := '';
  stok := '';
  lastChar := #0;
  strSep := #0; // for compiler
  inString := false;
  lineIndex := 1;
  while true do
  begin
    if not NextChar(ch) then
    begin
      AddToken(result, token, (lastChar <> #0) and IsSep(lastChar));
      exit;
    end;

    if ch in ['"', ''''] then
    begin
      stok := stok + ch;
      if inString then
      begin
        if ch = strSep then
        begin
          if PeekFor(strSep) then
            stok := stok + strSep
          else
          begin
            token := token + UnquoteIfNecessary(stok, strSep);
            inString := false;
            stok := '';
          end;
        end;
      end
      else
      begin
        strSep := ch;
        inString := true;
      end;
    end
    else if IsSep(ch) and not inString then
      AddToken(result, token, true)
    else
    begin
      if inString then
        stok := stok + ch
      else
        token := token + ch;
    end;
    lastChar := ch;
  end;
end;

在Delphi 10.2中,它给出了一个错误: [dcc32错误] commutil.pas(3101):E2267'ExtractTokens'的先前声明未标有'overload'指令

我不明白如何修复此错误!!!

1 个答案:

答案 0 :(得分:2)

线索在错误消息中。我们来看看吧。

  

E2267以前宣布的&#39; ExtractTokens&#39;未被标记为超载&#39;指令

显然你有一个名为ExtractTokens的函数的早期声明。找到它,你的解决方案将是显而易见的。

使用overload标记两个声明,或根据您的意图删除一个声明。