0

I have converted code from Delphi 6 32-bit to Delphi 11 64-bit, and in the source code we have used Fast String to use the FastReplace() and FastPos() functions.

I have tried to compile the FastStrings.pas unit file using Delphi 11 64-bit, but it raises a compilation error as it contains asm code. So, I have replaced the FastPos() function to Pos() to resolve the compilation error.

What could be an exact alternate method to including the FastPos() function that has the same functionality?

//The first thing to note here is that I am passing the SourceLength and FindLength
//As neither Source or Find will alter at any point during FastReplace there is
//no need to call the LENGTH subroutine each time !
function FastPos(const aSourceString, aFindString : string; const aSourceLen, aFindLen, StartPos : Integer) : Integer;
var
  JumpTable: TBMJumpTable;
begin
  //If this assert failed, it is because you passed 0 for StartPos, lowest value is 1 !!
  Assert(StartPos > 0);
  if aFindLen < 1 then begin
    Result := 0;
    exit;
  end;
  if aFindLen > aSourceLen then begin
    Result := 0;
    exit;
  end;

  MakeBMTable(PChar(aFindString), aFindLen, JumpTable);
  Result := Integer(BMPos(PChar(aSourceString) + (StartPos - 1), PChar(aFindString),aSourceLen - (StartPos-1), aFindLen, JumpTable));
  if Result > 0 then
    Result := Result - Integer(@aSourceString[1]) +1;
end;

I have used the StringReplace() function instead of FastReplace() and it works fine in Delphi 64-bit.

Kindly, provide any solution to implement FastPos() functionality in Delphi 11 64-bit.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 5
    You may just use the standard StringReplace and Pos functions and postpone the fast approach for when it is actually needed. Perhaps the current intrinsic routines are already fast enough. – Uwe Raabe Jul 27 '23 at 11:20
  • 2
    The standard string manipulation functions from Delphi have been reworked in the past to become much more faster then the ones back from D6, so the FastStrings unit isn't needed anymore. In contrast those function could be even slower now then the ones shipping with Delphi! – Delphi Coder Jul 27 '23 at 12:28
  • 1
    Latest Delphi version uses the FastCode `Pos()` pascal version for 64 bit compilation. The 32 bit is already the FastCode `Pos()` version but in asm. It is hard to get faster implementations. – LU RD Jul 27 '23 at 20:06
  • https://stackoverflow.com/a/20947429 see the update at the end of this answer regarding D11 Alexandria! – Delphi Coder Jul 28 '23 at 05:49

1 Answers1

1

I have used Pos() and it's working fine as required.