#1 2022-12-29 13:08:54

Greg0r
Member
Registered: 2019-01-28
Posts: 48

Be careful on PosEx from mORMot

is this bug or by design?
I found your function Arnaud over internet, problem is that that function does not work with those conditions:
- UTF8 char is used
- Project uses your mORMot

Then it uses first PosEx from mORMot which works buggy, forcing usage from native Delphi (StrUtils) fixes the issue.
Is this known for you or is that a bug?
Below mentioned function

function ExtractText(const Str: string; const Delim1, Delim2: string): string;
var
  pos1, pos2: integer;
begin
  result := '';
  pos1 := Pos(Delim1, Str);
  if pos1 > 0 then begin
    pos2 := PosEx(Delim2, Str, pos1+1);
    if pos2 > 0 then
      result := Copy(Str, pos1 + 1, pos2 - pos1 - 1);
  end;
end;

Offline

#2 2022-12-29 13:11:51

Greg0r
Member
Registered: 2019-01-28
Posts: 48

Re: Be careful on PosEx from mORMot

BTW: How Delphi determine which file/class has priority when functions have the same name? For example to how to force first use native in all code places and as second use other 3rd party libraries

Offline

#3 2022-12-29 17:09:06

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Be careful on PosEx from mORMot

@Greg0r
My guess is that PosEx() is not buggy.
Your code is buggy, because you are mixing string (= UnicodeString) and RawUtf8 strings.
PosEx() is for RawUtf8/Utf8String, whereas your ExtractText() function uses string.

So there are implicit string to/from RawUtf8 conversions, which are warned by the compiler IIRC, and is likely to make your code fail.
Please first fix your code, looking at the compiler messages.

Use mORMot PosExString() instead - as documented.
Or just use Pos() with an offset, from Delphi RTL, which is the standard way for string since years.

The units are resolved in inverse order of the "uses clauses" above the code: the latest unit has the precedence for symbol name resolution.
To ensure a function with a same name is called from a given unit, whatever order of the units are in the "uses" clause, prefix it with the unit name.
As a rule, I always put the mORMot units last in my code: after SysUtils and other units.

Offline

Board footer

Powered by FluxBB