簡體   English   中英

E2107操作數大小不匹配

[英]E2107 Operand size mismatch

我從D2007上線以來就使用了此功能,不記得在哪里。

但是現在在XE7中,它返回編譯錯誤:

“ E2107操作數大小不匹配”

    function FastCharPos(const aSource : string; const C: Char; StartPos : Integer) : Integer;
    var
        L : Integer;
    begin
        //If this assert failed, it is because you passed 0 for StartPos, lowest value is 1 !!
      Assert(StartPos > 0);

        Result := 0;
      L := Length(aSource);
        if L = 0 then exit;
      if StartPos > L then exit;
      Dec(StartPos);
        asm
          PUSH EDI                 //Preserve this register

          mov  EDI, aSource        //Point EDI at aSource
          add  EDI, StartPos
                mov  ECX, L              //Make a note of how many chars to search through
                sub  ECX, StartPos
                mov  AL,  C              //and which char we want :Error -"E2107 Operand size mismatch"
        @Loop:
                cmp  Al, [EDI]           //compare it against the SourceString
          jz   @Found
          inc  EDI
                dec  ECX
                jnz  @Loop
          jmp  @NotFound
        @Found:
          sub  EDI, aSource        //EDI has been incremented, so EDI-OrigAdress = Char pos !
          inc  EDI
          mov  Result,   EDI
        @NotFound:

          POP  EDI
        end;
    end;

function FastCharPosNoCase(const aSource : string; C: Char; StartPos : Integer) : Integer;
var
  L                           : Integer;
begin
  Result := 0;
    L := Length(aSource);
  if L = 0 then exit;
    if StartPos > L then exit;
  Dec(StartPos);
    if StartPos < 0 then StartPos := 0;

  asm
            PUSH EDI                 //Preserve this register
            PUSH EBX
      mov  EDX, GUpcaseLUT

      mov  EDI, aSource        //Point EDI at aSource
            add  EDI, StartPos
            mov  ECX, L              //Make a note of how many chars to search through
      sub  ECX, StartPos

            xor  EBX, EBX
            mov  BL,  C              //:Error -"E2107 Operand size mismatch"
      mov  AL, [EDX+EBX]
        @Loop:
            mov  BL, [EDI]
      inc  EDI
      cmp  Al, [EDX+EBX]
            jz   @Found
      dec  ECX
      jnz  @Loop
      jmp  @NotFound
        @Found:
      sub  EDI, aSource        //EDI has been incremented, so EDI-OrigAdress = Char pos !
      mov  Result,   EDI
        @NotFound:

      POP  EBX
            POP  EDI
    end;
end;

我需要將這兩個功能更新為XE7 win32?

我必須做什么?

謝謝。

該代碼是為Unicode Delphi之前的版本編寫的,其中Char是8位字符類型AnsiChar的別名。 在Delphi 2009及更高版本中, Char是16位字符類型WideChar的別名。

出現錯誤消息的原因是該代碼旨在對8位字符元素進行操作,但是您提供的是16位操作數。 該運算符需要8位操作數,但您提供了16位操作數。

Char更改為AnsiChar以使該代碼編譯並在所有版本的Delphi上按預期方式運行。

話雖如此,我建議您停止使用此代碼。 而是使用Pos 通常,最好使用內置庫函數。

您應該停止將舊的匯編程序版本用於字符串例程,而應使用內置庫函數。

如果您想趕緊前進,可以重新實現以下功能:

function FastCharPos(const aSource: string; const C: Char; StartPos: Integer): Integer; inline;
begin
  Result := Pos(C, aSource, StartPos);
end;

function FastCharPosNoCase(const aSource: string; C: Char; StartPos: Integer): Integer; inline;
begin
  Result := Pos(AnsiUppercase(C), AnsiUppercase(aSource), StartPos);
end;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM