[DUG] RFID - EAccess violation
Karl Reynolds
kreynolds at chocfishsoft.co.nz
Thu May 28 16:06:29 NZST 2015
*Incidentally, "buffer" is used in the original code - it receives the
keydata string via the call to StrPCopy. "key" ends up as effectively
@buffer[0]*
Oh right, I missed that! Then what I wrote was wrong, especially if the
function is expecting to write back over buffer.. Yes, we do really need to
know more about the function being called; in the absence of that
information though, it wouldn't hurt to initialise the arrays.
var
key, bufferr: PChar;
keydata, bufferrdata: array[0..255] of char;
...
begin
for i := 0 to 255 do
begin
if i <= 6 then
begin
keydata[i] := #255;
end
else keydata[i] := #0;
bufferrdata[i] := #0;
end;
key := PChar(@keydata);
bufferr := PChar(@buffdata);
receive := API_PCDRead(0,0,$00,10,1,key,bufferr);
...
(I called it keydata rather than buffer to save myself confusion :))
Cheers,
Carl
On Thu, May 28, 2015 at 3:41 PM, Jolyon Smith <jsmith at deltics.co.nz> wrote:
> Fair enough. That wasn't entirely clear so thought it worth clarifying in
> case the OP was confused into thinking this was somehow involved in the AV.
>
> (Incidentally, "buffer" is used in the original code - it receives the
> keydata string via the call to StrPCopy. "key" ends up as effectively
> @buffer[0]).
>
> On 28 May 2015 at 15:31, Karl Reynolds <kreynolds at chocfishsoft.co.nz>
> wrote:
>
>> Jolyon, I was pointing out a separate error that had nothing to do with
>> the AV he was getting.
>>
>> *> there looks to be an error in your code even if it works*
>>
>> Cheers,
>> Carl
>>
>> On Thu, May 28, 2015 at 2:43 PM, Jolyon Smith <jsmith at deltics.co.nz>
>> wrote:
>>
>>> @Carl,
>>>
>>> Although the code probably is incorrect in the way that it references
>>> buffer after the call, rather than bufferr, this in itself will not cause
>>> an AV since both buffer and bufferr are both statically allocated arrays
>>> and thus references to items in these arrays will be valid, even if not
>>> correct, as long as those references are within the bounds of the array,
>>> which they are in this case.
>>>
>>> On 28 May 2015 at 12:33, Karl Reynolds <kreynolds at chocfishsoft.co.nz>
>>> wrote:
>>>
>>>> I don't know the API_PCDRead function. But there looks to be an error
>>>> in your code even if it works. You are passing bufferr (two 'r's) to the
>>>> function but referring to buffer (one 'r') afterwards, which wasn't used
>>>> (unless there's other code you didn't show). So you need to look at that.
>>>>
>>>> That aside, for the bit leading up to the call, try something like:
>>>>
>>>> var
>>>> key, bufferr: PChar;
>>>> keydata: string;
>>>> buffdata: array[0..255] of char;
>>>> ...
>>>> begin
>>>> // Allocate a string of six consecutive $FFs
>>>> keydata := #255#255#255#255#255#255;
>>>>
>>>> // Convert to a PChar, an easy way to avoid having to allocate memory
>>>> explicitly
>>>> key := PChar(keydata);
>>>>
>>>> // Once again avoid having to allocate memory explicitly
>>>> // Point bufferr at the address of an array of 256 characters
>>>> bufferr := PChar(@buffdata);
>>>>
>>>> receive:=API_PCDRead(0,0,$00,10,1,key,bufferr);
>>>>
>>>> ...
>>>>
>>>> Cheers,
>>>> Carl
>>>>
>>>> On Thu, May 28, 2015 at 11:33 AM, Marshland Engineering <
>>>> marshland at marshland.co.nz> wrote:
>>>>
>>>>> Thanks for the replies.
>>>>>
>>>>> this is the line
>>>>>
>>>>> > receive:=API_PCDRead(0,0,$00,10,1,key,bufferr);
>>>>>
>>>>> I'm way out my depth with the workings of this function. I just do
>>>>> simple
>>>>> coding - A ex dBase3 programmer.
>>>>>
>>>>> I took the sample code that the RFID supplier gave, stripped off
>>>>> everything I
>>>>> didn't need other than the read line for RFID card and then copied the
>>>>> bits
>>>>> into my program which now crashes.
>>>>>
>>>>> I was wondering if the XPMENU call or something like that is
>>>>> interfering with
>>>>> other modules ?
>>>>>
>>>>> My debugging is limited to finding the line with the error.
>>>>>
>>>>> Both programs are run in Delphi 6, same machine and same environment.
>>>>>
>>>>> I can't find how to code this, where ever I put it, it crashes. -
>>>>> Expected
>>>>> expression but ARRAY found.
>>>>>
>>>>> const
>>>>> KEY = array[0..6] of Byte = ($FF,$FF,$FF,$FF,$FF,$FF,$00);
>>>>>
>>>>> Thanks Wallace.
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> NZ Borland Developers Group - Delphi mailing list
>>>>> Post: delphi at listserver.123.net.nz
>>>>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>>>>> Unsubscribe: send an email to delphi-request at listserver.123.net.nz
>>>>> with Subject: unsubscribe
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> NZ Borland Developers Group - Delphi mailing list
>>>> Post: delphi at listserver.123.net.nz
>>>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>>>> Unsubscribe: send an email to delphi-request at listserver.123.net.nz
>>>> with Subject: unsubscribe
>>>>
>>>
>>>
>>> _______________________________________________
>>> NZ Borland Developers Group - Delphi mailing list
>>> Post: delphi at listserver.123.net.nz
>>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>>> Unsubscribe: send an email to delphi-request at listserver.123.net.nz with
>>> Subject: unsubscribe
>>>
>>
>>
>> _______________________________________________
>> NZ Borland Developers Group - Delphi mailing list
>> Post: delphi at listserver.123.net.nz
>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>> Unsubscribe: send an email to delphi-request at listserver.123.net.nz with
>> Subject: unsubscribe
>>
>
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at listserver.123.net.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at listserver.123.net.nz with
> Subject: unsubscribe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20150528/4a3dbbac/attachment-0001.html
More information about the Delphi
mailing list