Exit Application Exception

Airbornz
2012-08-21
2013-01-13
  • Airbornz
    Airbornz
    2012-08-21

    I have a simple test app that is reading a pair of serial weighbridge simulators, utilising Asynch 4.07 on D7 running on XP.  I'm using packets to do the hard work for me - seems to work fine.

    When I close the App (click close button on form) I get "Bridgetest.exe encountered a problem and had to close . . ."  More info gives the exception code 0xC0000005.

    What is the correct way I should be doing things so ensure a graceful exit?  The documentation

    TIA
    Code (in it's entirety):
    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, OoMisc, AdPort, StdCtrls, AdPacket;

    type
      TForm1 = class(TForm)
        inbridge: TApdComPort;
        outbridge: TApdComPort;
        inbridgepacket: TApdDataPacket;
        outbridgepacket: TApdDataPacket;
        Edit1: TEdit;
        Edit2: TEdit;
        Label1: TLabel;
        Label2: TLabel;
        unstablepacket: TApdDataPacket;
        rbin: TRadioButton;
        rbout: TRadioButton;
        procedure inbridgepacketStringPacket(Sender: TObject; Data: String);
        procedure outbridgepacketStringPacket(Sender: TObject; Data: String);
        procedure FormCreate(Sender: TObject);
        procedure unstablepacketStringPacket(Sender: TObject; Data: String);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.inbridgepacketStringPacket(Sender: TObject; Data: String);
    begin
      edit1.Text := data;
      if rbin.Checked then
        rbin.Checked := false
      else
        rbin.Checked := true;
    end;

    procedure TForm1.outbridgepacketStringPacket(Sender: TObject;
      Data: String);
    begin
      edit2.Text := data;
      if rbout.Checked then
        rbout.Checked := false
      else
        rbout.Checked := true;
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      inbridgepacket.endString := #13 + #10 + #03;
      outbridgepacket.EndString := '    00' + #13;
      outbridgepacket.StartString := #02 + '10';
      unstablepacket.StartString := #02 + '18';
      inbridge.Open := true;
      outbridge.Open := true;
    end;

    procedure TForm1.unstablepacketStringPacket(Sender: TObject; Data: String);
    begin
      edit2.Text := 'UNSTABLE';
    end;

    end.