Random access violation on program exit

Forum for Delphi Discussion
shibz

Random access violation on program exit

Postby shibz » Tue Nov 18, 2008 6:14 am

Hi there,

I have made a time registration system using the RFID phidget, my program is based on the delphi sample code.

The problem I have is not a real problem, it's more of an annoyance..

What happens is this: I compile and run my program from within Delphi 7 Enterprise, the program then runs, I test if it's working properly with a couple rfid-tags and then exit the program via alt+f4.

Now most of the time that just closes the program and returns me to delphi so I can make further modifications, but about one in six times I run the program, when shutting it down I get an access violation.

Does anyone have an idea what can be causing this and how I can fix it?

Here's a screenshot of what happens:

ImageImage

fitchett
Site Admin
Posts: 259
Joined: Fri Dec 05, 2003 3:45 pm
Location: Canada
Contact:

Postby fitchett » Tue Nov 18, 2008 10:56 am

Can you post some code?

Chester

User avatar
Patrick
Lead Developer
Posts: 2907
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Postby Patrick » Tue Nov 18, 2008 11:22 am

do you close the reader before exiting?

shibz

Postby shibz » Tue Nov 18, 2008 2:20 pm

Yes, I have "rfid1.Close;" in my TForm1.FormCloseQuery.

Edit: here's some code, I stripped it down to bare minimum, to see if it wasn't any of my own (sql) code causing it..

Code: Select all

unit rfid;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Phidget21COMEvents, Phidget21COM_TLB, StdCtrls, MMSystem, FMTBcd,
  ExtCtrls, jpeg, ComCtrls;

type
  TForm1 = class(TForm)
    Phidget21COMIPhidgetRFIDEvents1: TPhidget21COMIPhidgetRFIDEvents;
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure Phidget21COMIPhidgetRFIDEvents1TagLost(Sender: TObject; const TagNumber: WideString);
    procedure Phidget21COMIPhidgetRFIDEvents1Detach(Sender: TObject);
    procedure Phidget21COMIPhidgetRFIDEvents1Attach(Sender: TObject);
    procedure Phidget21COMIPhidgetRFIDEvents1Tag(Sender: TObject; const TagNumber: WideString);
    procedure FormCreate(Sender: TObject);
    procedure UpdateTime(Sender: TObject);
    procedure ExitClick(Sender: TObject);
    procedure hudTagTimer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  rfid1 : IPhidgetRFID;
  MyManager : IPhidgetManager;
  beepsnd : PChar;
  beepsndc : PChar;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
    BorderStyle := bsNone;
    WindowState := wsMaximized;
    ShowCursor(false);
    beepsnd := PChar('chip-beep.wav');
    beepsndc := PChar('chip-beep-cancel1.wav');

    hudUser.Top := 194;
    hudUser.Left := 162;

    hudTag.Top := 326;
    hudTag.Left := 281;

    rfTime.Caption := FormatDateTime('yyy-mm-dd / hh:mm', Now);
   
    rfid1:=CoPhidgetRfid.Create;
    Phidget21COMIPhidgetRFIDEvents1.Connect(rfid1);
    rfid1.Open(-1);

    Form1.DoubleBuffered := true;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  ShowCursor(true);
  rfid1.AntennaOn := false;
  rfid1.LEDOn := false;
  rfid1.OutputState[1] := false;
  rfid1.OutputState[0] := false;
  rfid1.Close();
  CanClose := true;
end;

procedure TForm1.Phidget21COMIPhidgetRFIDEvents1Tag(Sender: TObject; const TagNumber: WideString);
var
  tagUser: string;
begin
  PlaySound(beepsnd, 0, SND_ASYNC);
  rfid1.LEDOn := true;
  rfid1.OutputState[1] := true;
  tagTimeout.Enabled := true;
end;

procedure TForm1.Phidget21COMIPhidgetRFIDEvents1TagLost(Sender: TObject; const TagNumber: WideString);
begin
  rfid1.LEDOn := false;
  rfid1.OutputState[1] := false;
  LTimeout.Caption := '3';
end;

procedure TForm1.Phidget21COMIPhidgetRFIDEvents1Attach(Sender: TObject);
begin
  rfSerial.Caption := String(rfid1.DeviceType+' verbonden. Serienummer #'+IntToStr(rfid1.SerialNumber));
  rfSerialShade.Caption := rfSerial.Caption;
  rfid1.AntennaOn := true;
  rfid1.LEDOn := false;
  rfid1.OutputState[1] := false;
  rfid1.OutputState[0] := false;
end;

procedure TForm1.Phidget21COMIPhidgetRFIDEvents1Detach(Sender: TObject);
begin
  rfSerial.Caption := String(rfid1.DeviceType+' losgekoppeld. Serienummer #'+IntToStr(rfid1.SerialNumber));
  rfSerialShade.Caption := rfSerial.Caption;
end;

procedure TForm1.UpdateTime(Sender: TObject);
begin
  rfTime.Caption := FormatDateTime('yyy-mm-dd / hh:mm', Now);
  rfTimeShade.Caption := rfTime.Caption;
end;

procedure TForm1.hudTagTimer(Sender: TObject);
begin
  LTimeout.Caption := IntToStr(StrToInt(LTimeout.Caption) - 1);
  if LTimeout.Caption = '0' then
  begin
    tagTimeout.Enabled := false;
    PlaySound(beepsndc, 0, SND_ASYNC);
  end;

 
end;

end.

shibz

Postby shibz » Wed Nov 19, 2008 4:05 am

Anothing thing I noticed is an excessive amount of registry activity, namely 2500 registry openkey/querykey/closekey events in 10 seconds, is that normal?

Log here: http://www.hastings.nl/dropbox/Regmon-phidget-log.txt

User avatar
Patrick
Lead Developer
Posts: 2907
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Postby Patrick » Wed Nov 19, 2008 10:46 am

Yes, that is normal - it is the library looking for device attaches / detaches.

-Patrick


Return to “Delphi”

Who is online

Users browsing this forum: No registered users and 1 guest