英文:
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 > 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.
答案1
得分: 1
我已经使用了 Pos()
,并且它按照要求正常工作。
英文:
I have used Pos()
and it's working fine as required.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论