#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13

    count EOL character


    I hve an app which reads ascii text from a serial port and recognises LF (line feed) as the end of line. I have a problem where one of the interfaces actually produces a single record over two lines. This means I have to process the data after the second LF. How would I modify the following code to take account of this.
    Code:
    procedure TMainForm.nrComm1AfterReceive(Com: TObject; Buffer: Pointer;
      Received: Cardinal);
    var i:integer;
    EolnChar:char;
    begin
    EolnChar:=#10; //end of string indicator.
      for i:=0 to Received-1 do
        if PChar(Buffer)[i]=EolnChar
          then begin
            //CR detected .... do something
            //sSearch := buffer;
            ProcessSearch(sSearch);
            sSearch := '';
          end
           //else accumulate string ...
           else sSearch:=sSearch+PChar(Buffer)[i];
    end;
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Is there some way for you to know that the data is continued on the next line or will you know only after you run ProcessSearch on it?
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2002
    Location
    UK
    Posts
    563
    Rep Power
    13
    by veiwing the text using vedit it seems as though cr/lf indicates the next line. unfortunately both lines can vary in length.
    i thought creating a var to count the lines and then process the data. something like

    Code:
    procedure TMainForm.nrComm1AfterReceive(Com: TObject; Buffer: Pointer;
      Received: Cardinal);
    
    var 
    i:integer;
    j:integer;
    EolnChar:char;
    begin
    EolnChar:=#10; //end of string indicator.
      for i:=0 to Received-1 do
        if PChar(Buffer)[i]=EolnChar
          then begin
            j++
                if j = 1 then begin
                         //CR detected .... do something
                         //sSearch := buffer;
                         ProcessSearch(sSearch);
                         sSearch := '';
                         j := 0;
               end
          end
           //else accumulate string ...
           else sSearch:=sSearch+PChar(Buffer)[i];
    end;
    Although I do not have time to try it. WhaDaYaTink?

IMN logo majestic logo threadwatch logo seochat tools logo