需要建议在Delphi中替代使用Faststring.pas。

huangapple go评论92阅读模式
英文:

Need suggestion to use alternate for Faststring.pas in delphi

问题

我已将代码从Delphi 6 32位转换为Delphi 11 64位,在源代码中,我们使用了Fast String来使用FastReplace()FastPos()函数。

我尝试使用Delphi 11 64位编译FastStrings.pas单元文件,但由于它包含asm代码,它引发了编译错误。因此,我将FastPos()函数替换为Pos()以解决编译错误。

有没有一个精确的替代方法来包括具有相同功能的FastPos()函数?

//这里要注意的第一件事是,我正在传递SourceLength和FindLength
//由于在FastReplace过程中Source或Find都不会在任何时候改变,所以每次调用LENGTH子例程都是没有必要的!
function FastPos(const aSourceString, aFindString : string; const aSourceLen, aFindLen, StartPos : Integer) : Integer;
var
  JumpTable: TBMJumpTable;
begin
  //如果这个断言失败了,那是因为你为StartPos传递了0,最小值是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;

我已经使用了StringReplace()函数代替了FastReplace(),在Delphi 64位中运行良好。

请提供在Delphi 11 64位中实现FastPos()功能的任何解决方案。

英文:

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 &gt; 0);
  if aFindLen &lt; 1 then begin
    Result := 0;
    exit;
  end;
  if aFindLen &gt; 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 &gt; 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.

答案1

得分: 1

我已经使用了 Pos(),并且它按照要求正常工作。

英文:

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

huangapple
  • 本文由 发表于 2023年7月27日 19:09:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76779151.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定