Recent

Author Topic: Trouble with parseing(SOLVED)  (Read 3691 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1054
Trouble with parseing(SOLVED)
« on: October 16, 2021, 08:19:16 am »
I'm gettin an error at line 18: unit1.pas(870,12) Error: Operator is not overloaded: - "AnsiString". I don't understand?

Var 2S : String = '    Notes: aaaa bb ccccccc  dddddddddd eeeeeee fffffff ggggg hh iiiiiii jjjjj kkkkkkkkkk llllllllll m n oooooooo pppppp qqqqqq rrrrrr sssssssss ttttt uuuuuuuuuuuuuu vvvvvv wwwwwwwww x yy zzzzzzz.                                                       

Sl is a TstringList I'm passing in and stores the reply.

It work somewhat but not really good. And with the error not at all

Call:  parseforlength(sToParse, SL );

Code: Pascal  [Select][+][-]
  1.  procedure TForm1.ParseForLength(const sToParse : String;  SL: TStringList);
  2.   var S : String;
  3.    sInsert : String[14] = '              ';
  4.    p1, p2,s2P, Lgth : SizeInt;
  5.    sSize : Integer = 107;
  6.    s2Parse : String;  
  7.  begin                              
  8.    s2Parse := sToParse;
  9.    s2P := Length(s2Parse);
  10.    if s2P <= sSize then begin SL.ADD(s2Parse); exit; end;
  11.    p1 := 5;
  12.   repeat
  13.    p1 := PosEx(' ', sToParse, p1);
  14.    if ( p1 > 0 ) then begin
  15.       p2 := PosEx(' ', s2Parse, p1 + 1 );
  16.       if (p2 > sSize) then begin
  17.          Insert( '|',s2Parse, P1 );             -
  18.          S := Copy2SymbDel(s2Parse, '|');
  19.          SL.Add(S);
  20.          s2Parse := Concat( sInsert, s2Parse);
  21.          if ( Lgth = 0 ) or ( s2P < sSize ) or ( p1 = 0) then begin
  22.              P1 := 0; P2 := 0;
  23.              s2Parse := Concat( sInsert, s2Parse);
  24.              SL.Add(s2Parse);
  25.              exit;
  26.          end else begin
  27.           p1 := 8; P2 := 1;
  28.          end;
  29.        end;
  30.         P1 := p2 + 1;
  31.      end;
  32.    until (p1 = 0) or (p2 = 0);
  33.  end;  

Results should be:

'    Notes: aaaa bb ccccccc dddddddddd eeeeeee fffffff ggggg hh iiiiiii jjjjj kkkkkkkk
               llllllllll m n oooooooo pppppp qqqqqq rrrrrr sssssssss ttttt uuuuuuuuuuuuu
               vvvvvv wwwwwwwww x yy zzzzzzz.

Thanks     
« Last Edit: October 17, 2021, 01:27:12 am by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

dseligo

  • Sr. Member
  • ****
  • Posts: 375
Re: Trouble with parseing
« Reply #1 on: October 16, 2021, 09:35:14 am »
Code: Pascal  [Select][+][-]
  1.          Insert( '|',s2Parse, P1 );             -

You have minus ('-') at the end of line 17.

ASerge

  • Hero Member
  • *****
  • Posts: 1886
Re: Trouble with parseing
« Reply #2 on: October 16, 2021, 09:59:35 am »
See also [SOLVED] WrapText with indent?
But there is a drawback: in FPC, the WrapText function makes a break after the maximum length (in Delphi before).

JLWest

  • Hero Member
  • *****
  • Posts: 1054
Re: Trouble with parseing
« Reply #3 on: October 16, 2021, 05:07:15 pm »
@dseligo Thanks
@ ASerge

I don't know how I could use that code.

After fixing the issue I find the parser get's in an endless loop. Can't figure it out.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

bytebites

  • Sr. Member
  • ****
  • Posts: 424
Re: Trouble with parseing
« Reply #4 on: October 16, 2021, 07:23:45 pm »
Variable Lgth is not initialised.

JLWest

  • Hero Member
  • *****
  • Posts: 1054
Re: Trouble with parseing
« Reply #5 on: October 16, 2021, 08:16:05 pm »
@bytebites

  ?  Variable Lgth is not initialised.

 Don't understand.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

bytebites

  • Sr. Member
  • ****
  • Posts: 424
Re: Trouble with parseing
« Reply #6 on: October 16, 2021, 08:31:32 pm »
It has not defined value.

dseligo

  • Sr. Member
  • ****
  • Posts: 375
Re: Trouble with parseing(SOLVED)
« Reply #7 on: October 17, 2021, 01:27:26 pm »
Try this:
Code: Pascal  [Select][+][-]
  1. procedure ParseForLengthDS(const AStoParse: String;  Asl: TStringList);
  2. var sInsert: String = '           ';
  3.     iSSize: Integer = 86;
  4.     iPos: Integer;
  5.     s2Parse: String;
  6. begin
  7.   s2Parse := AStoParse;
  8.   While s2Parse <> '' do begin
  9.     If Length(s2Parse) <= iSSize then begin
  10.       Asl.Append(s2Parse);
  11.       Exit;
  12.     end;
  13.  
  14.     iPos := RPosEx(' ', s2Parse, iSSize);
  15.     If iPos > Length(sInsert) then begin
  16.       Asl.Append(Copy(s2Parse, 1, iPos - 1));
  17.       s2Parse := sInsert + Copy(s2Parse, iPos + 1, MaxInt);
  18.     end
  19.     else begin
  20.       // in case space is not found, cut at specific length
  21.       Asl.Append(Copy(s2Parse,1,iSSize));
  22.       s2Parse := sInsert + Copy(s2Parse, iSSize + 1, MaxInt);
  23.  
  24.       // other option: try to find space past the specific length and cut there:
  25.       //iPos := PosEx(' ', s2Parse, iSSize);
  26.       //If iPos > 0 then begin
  27.       //  Asl.Append(Copy(s2Parse, 1, iPos - 1));
  28.       //  s2Parse := sInsert + Copy(s2Parse, iPos + 1, MaxInt);
  29.       //end
  30.       //else begin
  31.       //  Asl.Append(s2Parse);
  32.       //  Exit;
  33.       //end;
  34.     end;
  35.   end;
  36. end;

 

TinyPortal © 2005-2018