Search code examples
delphi64-bitdelphi-11-alexandria

Need suggestion to use alternate for Faststring.pas in delphi


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.


Solution

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