2015-02-03 5 views
0

D2007부터이 함수를 사용합니다. 온라인 상태 일 때 기억하지 않습니다.E2107 피연산자 크기가 맞지 않습니다.

하지만 지금 XE7에서이 컴파일 오류 반환 :

"E2107 Operand size mismatch"

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에서 이러한 두 가지 기능을 업데이트해야합니까?

어떻게해야합니까?

감사합니다.

답변

2

이 코드는 유니 코드 Delphi 용으로 작성된 것이며 CharAnsiChar의 8 비트 문자 유형에 대한 별칭입니다. Delphi 2009 및 이후 버전에서 CharWideChar의 16 비트 문자 유형에 대한 별칭입니다.

오류 메시지의 이유는 코드가 8 비트 문자 요소에서 작동하도록되어 있지만 16 비트 피연산자를 제공하고 있기 때문입니다. 연산자는 8 비트 피연산자를 예상하지만 16 비트 피연산자를 제공했습니다.

Char에서 AnsiChar으로 변경하면이 코드가 모든 버전의 Delphi에서 컴파일되고 동작합니다.

그런데이 코드 사용을 중단하는 것이 좋습니다. 대신 Pos을 사용하십시오. 일반적으로 내장 라이브러리 함수를 사용하는 것이 좋습니다.

+0

예 그것이 내가 XE7에 D2007에서 뭐하는 거지,하지만 지금은 그때 일을하고 몇 가지 코드가 필요합니다 : 당신이 서둘러 이동하려면

당신은 다음과 같이 당신에게 기능을 구현할 수 있습니다 나는 모두 업 그레 이드하고 청소합니다. 감사 – Jlouro

1

문자열 루틴의 경우 이전 어셈블러 버전 사용을 중단하고 기본 제공 라이브러리 함수를 사용해야합니다.

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; 
관련 문제