<div dir="ltr">Are you able to debug which line of code the error is occuring on?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 27, 2015 at 1:56 PM, Marshland Engineering <span dir="ltr"><<a href="mailto:marshland@marshland.co.nz" target="_blank">marshland@marshland.co.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm a bit out my depth. Is there something I have missed ?<br>
<br>
EAccess violation at address 000000000<br>
<br>
I purchased an RFID reader with sample code. I stripped out what was not<br>
necessary and ended up with this.<br>
<br>
Sorry for the long code<br>
<br>
**************************************************************<br>
<br>
unit Unit1;<br>
<br>
interface<br>
<br>
uses<br>
Windows, Messages, SysUtils, Variants, Classes, Controls, Forms,<br>
ComCtrls, StdCtrls, XPMenu, ExtCtrls;<br>
<br>
type<br>
TForm1 = class(TForm)<br>
showm: TRichEdit;<br>
Button1: TButton;<br>
procedure falsereason(s:string);<br>
procedure bReadClick(Sender: TObject);<br>
private<br>
{ Private declarations }<br>
public<br>
{ Public declarations }<br>
end;<br>
<br>
function<br>
API_PCDRead(comHandle:Thandle;DeviceAddress:integer;mode:byte;add_blk,num_blk:integer;<br>
snr,buffer:pchar):integer;stdcall;external 'mi.dll';<br>
<br>
var<br>
Form1: TForm1;<br>
comhandle : Thandle ;<br>
reason:string;<br>
implementation<br>
<br>
{$R *.dfm}<br>
<br>
procedure TForm1.falsereason(s:string);<br>
begin<br>
if s='' then begin reason:=''; exit; end;<br>
if s='00' then begin reason:=''; exit ; end;<br>
etc<br>
if s='96' then begin reason:='The Operation Do Not Success....'; exit;<br>
end;<br>
end;<br>
<br>
procedure TForm1.bReadClick(Sender: TObject);<br>
var<br>
buffer,bufferr:array [0..255] of char;<br>
receive,i :integer;<br>
keydata,cardnum,showmemo:string;<br>
key : pchar;<br>
begin<br>
setlength(keydata,6);<br>
for i:=1 to 6 do begin<br>
keydata[i]:=Chr(StrToInt('$FF'));<br>
end;<br>
key:=StrPCopy(buffer,keydata);<br>
receive:=API_PCDRead(0,0,$00,10,1,key,bufferr);<br>
case receive of<br>
0:begin<br>
for i:=0 to 3 do begin<br>
cardnum:=cardnum+ inttohex(ord(buffer[i]),2);<br>
end;<br>
showm.Lines.Add('Number :'+cardnum);<br>
end;<br>
1:begin<br>
falsereason(inttohex(ord(bufferr[0]),2));<br>
showm.Lines.Add(reason+#13#10);<br>
end<br>
else<br>
showm.Lines.Add('error,no data receive...'+#13#10);<br>
end;<br>
end;<br>
<br>
end.<br>
****************************************************************<br>
I added the above to my code and it complies but crashes when I do a receive.<br>
EAccess<br>
<br>
<br>
unit uMain;<br>
<br>
interface<br>
<br>
uses<br>
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>
Dialogs, Grids, DBGrids, Menus, ComCtrls, StdCtrls, Printers, DBCtrls,<br>
Mask, ExtCtrls, IniFiles, DB, ShellAPI, XPMenu;<br>
<br>
<br>
type<br>
TfMain = class(TForm)<br>
pcMembers: TPageControl;<br>
Members: TTabSheet;<br>
Events: TTabSheet;<br>
DBGrid1: TDBGrid;<br>
DBGrid4: TDBGrid;<br>
DBGrid5: TDBGrid;<br>
Label3: TLabel;<br>
bFees: TButton;<br>
Button1: TButton;<br>
bEmail: TButton;<br>
dbgMembers: TDBGrid;<br>
Label5: TLabel;<br>
Label7: TLabel;<br>
dbgFeesMem: TDBGrid;<br>
dbgSubs: TDBGrid;<br>
Label4: TLabel;<br>
Label2: TLabel;<br>
puSubs: TPopupMenu;<br>
puSubsAdd: TMenuItem;<br>
puSubsDel: TMenuItem;<br>
puFeesListPrinter: TMenuItem;<br>
puFeesListScreen: TMenuItem;<br>
upFeesCardsNotSent: TMenuItem;<br>
PrintSet1: TPrinterSetupDialog;<br>
puEventFees: TPopupMenu;<br>
puFeesAdd: TMenuItem;<br>
puFeesDelete: TMenuItem;<br>
puFeesList: TMenuItem;<br>
puMembers: TPopupMenu;<br>
puAddMember: TMenuItem;<br>
puDeleteMember: TMenuItem;<br>
puBikes: TPopupMenu;<br>
puAddBike: TMenuItem;<br>
puDeleteBike: TMenuItem;<br>
dbmNotes: TDBMemo;<br>
Label6: TLabel;<br>
dbgIncident: TDBGrid;<br>
Label8: TLabel;<br>
PrintDialog1: TPrintDialog;<br>
puIncident: TPopupMenu;<br>
AddIncident1: TMenuItem;<br>
DeleteIncident1: TMenuItem;<br>
dtpMainDate: TDateTimePicker;<br>
DBEdit1: TDBEdit;<br>
Label1: TLabel;<br>
Label9: TLabel;<br>
cbMainYear: TComboBox;<br>
DBGrid2: TDBGrid;<br>
bPostFees: TButton;<br>
Button2: TButton;<br>
eCardNumber: TEdit;<br>
procedure dbgMembersDblClick(Sender: TObject);<br>
procedure FormCreate(Sender: TObject);<br>
procedure dbgSubsDblClick(Sender: TObject);<br>
procedure puSubsAddClick(Sender: TObject);<br>
procedure puSubsDelClick(Sender: TObject);<br>
procedure upFeesCardsNotSentClick(Sender: TObject);<br>
procedure puFeesListPrinterClick(Sender: TObject);<br>
procedure FormShow(Sender: TObject);<br>
procedure dbmNotesExit(Sender: TObject);<br>
procedure puFeesAddClick(Sender: TObject);<br>
procedure puFeesDeleteClick(Sender: TObject);<br>
procedure dbgFeesDblClick(Sender: TObject);<br>
procedure dbgMembersKeyPress(Sender: TObject; var Key: Char);<br>
procedure puFeesListClick(Sender: TObject);<br>
procedure Button1Click(Sender: TObject);<br>
procedure puAddMemberClick(Sender: TObject);<br>
procedure puDeleteMemberClick(Sender: TObject);<br>
procedure puAddBikeClick(Sender: TObject);<br>
procedure puDeleteBikeClick(Sender: TObject);<br>
procedure DBGrid2DblClick(Sender: TObject);<br>
procedure dbmNotesEnter(Sender: TObject);<br>
procedure puFeesListScreenClick(Sender: TObject);<br>
procedure bEmailClick(Sender: TObject);<br>
procedure DBGrid3ColExit(Sender: TObject);<br>
procedure dbgIncidentCellClick(Column: TColumn);<br>
procedure AddIncident1Click(Sender: TObject);<br>
procedure DeleteIncident1Click(Sender: TObject);<br>
procedure MembersShow(Sender: TObject);<br>
procedure Button2Click(Sender: TObject);<br>
procedure falsereason(s:string);<br>
private<br>
{ Private declarations }<br>
public<br>
sKey:String;<br>
bFeesFirstTime:Boolean;<br>
end;<br>
<br>
function<br>
API_PCDRead(comHandle:Thandle;DeviceAddress:integer;mode:byte;add_blk,num_blk:integer;<br>
snr,buffer:pchar):integer;stdcall;external 'mi.dll';<br>
<br>
var<br>
fMain:TfMain;<br>
comhandle:Thandle ;<br>
Reason:String;<br>
<br>
implementation<br>
<br>
uses uDM, uMembers, uSubs, uMemCards, uEventFees, uLogon, uBikes, uMemoShow,<br>
uEmail, uIncident;<br>
<br>
{$R *.dfm}<br>
<br>
procedure TfMain.falsereason(s:string);<br>
begin<br>
if s='' then begin reason:=''; exit; end;<br>
if s='00' then begin reason:=''; exit ; end;<br>
etc<br>
if s='95' then begin reason:='The lock Operation Do Not Success....';<br>
exit; end;<br>
if s='96' then begin reason:='The Operation Do Not Success....'; exit;<br>
end;<br>
end;<br>
<br>
<br>
******** My other code,<br>
<br>
procedure TfMain.Button2Click(Sender: TObject);<br>
var<br>
buffer,bufferr:array [0..255] of char;<br>
receive,i :integer;<br>
keydata,cardnum,showmemo:string;<br>
key : pchar;<br>
begin<br>
setlength(keydata,6);<br>
for i:=1 to 6 do begin<br>
keydata[i]:=Chr(StrToInt('$FF'));<br>
end;<br>
key:=StrPCopy(buffer,keydata);<br>
receive:=API_PCDRead(0,0,$00,10,1,key,bufferr);<br>
case receive of<br>
0:begin<br>
for i:=0 to 3 do begin<br>
cardnum:=cardnum+ inttohex(ord(buffer[i]),2);<br>
end;<br>
showm.Lines.Add('Number :'+cardnum);<br>
end;<br>
1:begin<br>
falsereason(inttohex(ord(bufferr[0]),2));<br>
showm.Lines.Add(reason+#13#10);<br>
end<br>
else<br>
showm.Lines.Add('error,no data receive...'+#13#10);<br>
end;<br>
end;<br>
<br>
end.<br>
<br>
_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe<br>
</blockquote></div><br></div>