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

Jeppe Græsdal Johansen jeppe at j-software.dk
Thu Apr 18 08:14:41 CEST 2013


Den 18-04-2013 07:57, Reinier Olislagers skrev:
> 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}
>
Since you have a typed const pointer instead of an untyped const 
parameter, you need to do this:

System.IndexByte(PByte(Buffer)^, Length, Chr);




More information about the fpc-pascal mailing list