* * *

Author Topic: How can I catch this Error or check to nil?  (Read 436 times)

Soner A.

  • Full Member
  • ***
  • Posts: 127
    • My Blog
How can I catch this Error or check to nil?
« on: March 15, 2017, 10:31:49 pm »
Hello,
i have following code from 3rd part:
Code: Pascal  [Select]
  1. {$MODE DELPHI } // <--- it is compiled with Delphi-Mode
  2.  
  3. // PDataSetRecInfo ist Pointer to Record TDataSetRecInfo
  4. // aBuffer is PChar
  5. // dsRecInfoOfs is Integer;
  6. //..
  7.         with PDataSetRecInfo(aBuffer + dsRecInfoOfs)^ do begin
  8.           riBookmarkFlag := bfCurrent;                       //sometimes error here
  9.           riRecNo := 0;
  10.         end;
  11. //..
  12.  

Sometimes the programm crashs with Errorcode:
<TDataSetRecInfo>= cannot access memory at adress 0x58

It tried without success:
Code: Pascal  [Select]
  1. {$MODE DELPHI } // <--- it is compiled with Delphi-Mode
  2.      if PDataSetRecInfo(aBuffer + dsRecInfoOfs)<>nil then //don't helps, it passes every time
  3.         with PDataSetRecInfo(aBuffer + dsRecInfoOfs)^ do begin
  4.           riBookmarkFlag := bfCurrent;                       //sometimes error here
  5.           riRecNo := 0;
  6.         end;
  7.  

Does anyone know how can I catch this Error or check to nil?

I use latest Lazarus version with fixes-svn, fpc latest official, Windows 7, All 32Bit

ASerge

  • Full Member
  • ***
  • Posts: 235
Re: How can I catch this Error or check to nil?
« Reply #1 on: March 15, 2017, 10:44:50 pm »
...or check to nil?
Code: Pascal  [Select]
  1. if aBuffer <> nil then

Soner A.

  • Full Member
  • ***
  • Posts: 127
    • My Blog
Re: How can I catch this Error or check to nil?
« Reply #2 on: March 15, 2017, 10:55:59 pm »
Thanks, so easy I didn't see it  :-[
I use latest Lazarus version with fixes-svn, fpc latest official, Windows 7, All 32Bit

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 553
    • Burdjia
Re: How can I catch this Error or check to nil?
« Reply #3 on: March 17, 2017, 07:43:35 pm »
Just to clarify:
Code: Pascal  [Select]
  1.      if PDataSetRecInfo(aBuffer + dsRecInfoOfs)<>nil then //don't helps, it passes every time
This doesn't help because NIL is a pointer to address x00000000, so NIL + anything <> NIL is TRUE in all cases.

Kays

  • Jr. Member
  • **
  • Posts: 53
  • Whasup!?
    • KaiBurghardt.de
Re: How can I catch this Error or check to nil?
« Reply #4 on: March 19, 2017, 01:17:43 am »
Code: Pascal  [Select]
  1. if aBuffer <> nil then
I like my code more descriptive:
Code: Pascal  [Select]
  1. if assigned(aBuffer) then
http://www.freepascal.org/docs-html/rtl/system/assigned.html
Yours Sincerely
Kai Burghardt

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus