Hi Scorpions,
Just to upset every I have changed the code so that there is some threading in it (picked up along the way), But I am getting the same problem.
The first line is processed properly. The next line is not. It seems as though an additional empty line is included when I print to a richedit.
The information I recieve on the com port is
A201 --> N01 23/01/04 12:57 00:00:05 0 ST I 07966323260...............
A201 --> N01 23/01/04 12:58 00:00:11 0 ST I 0800282212................
The first line is present to the sql query as:
--------------------------------------------------
A201 --> N01 23/01/04 12:57 00:00:05 0 ST I 07966323260...............
The next line is presented as:
--------------------------------------------------
//note the additional line
A201 --> N01 23/01/04 12:58 00:00:11 0 ST I 0800282212................
All other lines are presented the same way afterwards. It seems as though CR is added to the beginning of the line to be processed.
How can I get rid of the additional line?
This is the code affecting it.
Code:
procedure TMainForm.nrComm1AfterReceive(Com: TObject; Buffer: Pointer;
Received: Cardinal);
var
i : integer;
begin
bFillingBuffer := True;
for i := 0 to Received-1 do
begin
if iCharCount >= sizeof(LargeBuffer) then
// does nothing. buffer full. loose of received chars
else
begin
// there are space left in buffer
LargeBuffer[iTail] := PChar(Buffer)[i]; // save char in buffer
Inc(iTail); // move pointer forward
Inc(iCharCount); // count char in buffer
if iTail = sizeof(LargeBuffer) then iTail := 0; // WRAP
end;
end;
bFillingBuffer := False;
end;
procedure TMainForm.Timer1Timer(Sender: TObject);
var
I, N : Integer;
C : Char;
begin
if iCharCount <= 0 then Exit; // nothing to do
while bFillingBuffer do ; // wait if processing receive buffer (synchronize)
N := iCharCount;
for I := 0 to N-1 do
begin
C := LargeBuffer[iHead]; // peak a buffered char
Inc(iHead); // move pointer forward
if iHead = sizeof(LargeBuffer) then iHead := 0; // WRAP
if C <> #13 then
sSearch := sSearch + C // concatenated the character
else
begin
Richedit1.Lines.Add(sSearch);
ProcessSearch(sSearch); // create a procedure to do the database task
// keep in mind the time wasted there
sSearch := ''; // clear for next string
end;
end;
while bFillingBuffer do ; // wait if processing receive buffer (synchronize)
iCharCount := iCharCount - N; // free space in buffer
end;
WhaDaYaTink?