[fpc-pascal] Bending System.IndexByte to my will!!?

Reinier Olislagers reinierolislagers at gmail.com
Thu Apr 18 07:57:04 CEST 2013


Hi all,

(FPC 2.6.2 x86, trunk x64, on Windows; found similar behaviour on Linux x64)

Busy getting DBase III memo support correct ;)

In fcl-db\src\dbase\dbf_common.pas we find this part used to e.g. find
end of file ($1A/ASCII 26) markers in a buffer with memo data: [1]

The problem is: the first MemScan function doesn't work:
System.IndexByte just always return -1 even if the character is there.
Tried system.indexbyte with a simple test program and of course it worked.
If I comment out $ifdef fpc to force use of the second function, the $1A
is found perfectly.

Where lies the problem?

Thanks,
Reinier

[1]
{$ifdef FPC}
function MemScan(const Buffer: Pointer; Chr: Byte; Length: Integer):
Pointer;
var
  I: Integer;
begin
  I := System.IndexByte(Buffer, Length, Chr);
  if I = -1 then
    Result := nil
  else
    Result := Buffer+I;
end;

{$else}

function MemScan(const Buffer: Pointer; Chr: Byte; Length: Integer):
Pointer;
asm
        PUSH    EDI
        MOV     EDI,Buffer
        MOV     AL, Chr
        MOV     ECX,Length
        REPNE   SCASB
        MOV     EAX,0
        JNE     @@1
        MOV     EAX,EDI
        DEC     EAX
@@1:    POP     EDI
end;

{$endif}



More information about the fpc-pascal mailing list