Exported from Bugzilla, issue 3700.
--- Comment added on 8/16/2002 3:58:08 PM ---
Tim Schuerewegen, .general, 8/16, "TApdDataPacket bug".
Another day (actually half a day) spent in the bowels of the horrifying
monster named APRO :)
Try giving a datapacket whose EndString = "NNNN" following string :
"N"<CR><LF>"NN"<CR><LF>"NNN"<CR><LF>"NN"<CR><LF>"N"<CR><LF>"NNNN"
What happens? It will trigger the OnStringPacket after 3 x "N" instead of 4
x "N" :(
Why? Because Delphi 4 (dunno about other versions) is optimizing a for loop
by caching the loop end value when that value is changed inside the loop
(which is part of APRO's logic). I tried playing with "{$O+}" and "{$O-}"
but it did not seem to do anything.
Back to my "NNNN" ... when APRO finds the <CR> after the 3rd sequential "N",
the loop is executed, the 1st iteration will go from 2 to 4 (EndMatchPos)
and the 2nd should go from 2 to 1 (EndMatchPos) because no match was found,
but Delphi has cached EndMatchPos and will iterate 3 times (J=2,J=3,J=4)
instead of less (my case) or more.
I have changed the for loop into a while loop which seems to work, thus
defeating Delphi's caching logic :)
Unit AdPacket.pas
procedure TApdDataPacket.ProcessData(StartPtr : Integer);
...
Match := False;
EndMatchStart := I-1;
{for j := 2 to EndMatchPos do begin}
{!!!}
J := 2;
{!!!}
while (J <= EndMatchPos) do begin
{!!!}
...
if Match then begin
inc(EndMatchPos);
break;
{end}
{!!!}
end;
{!!!}
Inc(J);
{!!!}
end;
if not Match then begin
...
end;
--- Comment added on 8/16/2002 4:00:18 PM ---
verified with following code (2 port/terminals, via nullmodem):
procedure TForm1.Button1Click(Sender: TObject);
begin
ApdDataPacket1.EndString := 'NNNN';
ApdDataPacket1.EndCond := [ecString};
ApdDataPacket1.StartString := '1';
ApdDataPacket1.StartCond := scString; // OK
ApdDataPacket1.StartCond := scAnyData; // fails
ApdComPort2.Output := '1N'#13#10'NN'#13#10'NNN'#13#10'NN'#13#10'N'#13#10'NNNN';
end;
procedure TForm1.ApdDataPacket1StringPacket(Sender: TObject; Data: String);
begin
ListBox1.Items.Add(Data);
end;
Logged In: YES
user_id=84969
Originator: NO
Fixed in 4.07 RC3