[Lazarus] [resulved] How to use TRegExpr class (in synregexpr.pas)

Mark Morgan Lloyd markMLl.lazarus at telemetry.co.uk
Thu Oct 24 19:31:11 CEST 2013

FreeMan wrote:
> Yes Mark, you rigth.
> This code is working now, Problem was space char in EDT_IP.Text, it 
> comes from format. This is normal, but at this time, why "Trim" function 
> NOT DELETE space char ????? is this bug ?
> var Q : String;Const WhiteSpace = [#0..' '];
>     function My_Trim(S : string): String;     var I: Integer;     
> begin       Result := S;       Try        I := 1;        while 
> I<Length(S)do Begin         if S[I]in WhiteSpace then 
> Delete(S,I,1)         else Inc(I,1);        end;    // while        
> Result := S;       Except       end;     end;
> //copied from /fpc271/rtl/objpas/sysutils/sysstr.inc  line 524     
> function Trim_(const S: string): string;     var Ofs, Len: integer;     
> begin       len := Length(S);       while (Len>0) and (S[Len] in 
> WhiteSpace) do        dec(Len);       Ofs := 1;       while (Ofs<=Len) 
> and (S[Ofs] in WhiteSpace) do        Inc(Ofs);       result := Copy(S, 
> Ofs, 1 + Len - Ofs);     end ;begin   Q := Trim(EDT_IP.Text);// space 
> not deleted   Q := Trim_(EDT_IP.Text);// space not deleted   Q := 
> My_Trim(EDT_IP.Text); // space DELETED   if IP4OK(Q)then 
> begin..............

By the time that arrived here its formatting had been completely lost 
(as you can see above), but it doesn't look to bad in the archive 
so I'm not entirely sure what's going on.

I'd suggest using a supported compiler rather than the development one, 
i.e. 2.6.x not 2.7.x. I'd also suggest not copying around code fragments 
gratuitously, because there are plenty of ways that things can behave 
differently depending on the compiler mode.

/If/ it still fails with the supported compiler version, then give us a 
minimal compilable program that we can test, rather than just a fragment 
without context.

Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

More information about the Lazarus mailing list