D7 Multi-Port Multi-Packet Exception


  • 2012-09-16

    I'm using V5.00 on Delphi7 with a multi serial port application.  Each port has 2 or 3 data packets defined against it.

    When exiting, execution is stopped in adPacket.pas at line 597 "for i := 0 to pred(PacketList.Count) do" with an EAccessViolation.

    I think this is because when closing off 2 ports, packetlist gets destroyed when the first port is closed, and the exception is raised when an attempt is made to destroy packetlist for the second time.  If I reduce to one port and it's packets, the program exits gracefully.

    I've tried to put a try block around the code above to no avail.

    What will be my salvation?  I have made this app by literally dropping my components on the form and configuring, so is not multithreaded.  Does anyone have some tips or codes samples that might help?



  • 2012-09-27

    Oh thank god!

    Found the answer, at least one that seems to work for me.

    Rather than dropping the objects on the form, I have explicitly created my packets in TForm1.Formcreate like this:
      weightpack := Tapddatapacket.Create(nil);
      with weightpack do
          StartString := #02 + '10';
          EndCond := ;
          EndString := '00' + #13;
          ComPort := inbridge;
          PacketSize := 0;
          IncludeStrings := False;
          OnStringPacket := ApdDataPacket1StringPacket;
          Enabled := true;

    The Packet object vars are defined in the global section.  eg:
      Form1: TForm1;
      gbExpectingACK, gbgotACK, gbgotNAK, gbapproved: boolean;
      AckPack, NakPack, DatPack, WeightPack, USPack: TApdDataPacket;

    I am not doing any destroy operations when exiting either.
    I've ended up using Apro 4.07 on Delphi7.
    Hope this helps someone.  You'll find this topic on the Embarcadero forum as well.