Recent

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

SunyD

  • Guest
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?


ASerge

  • Hero Member
  • *****
  • Posts: 2242
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

SunyD

  • Guest
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  :-[

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • 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.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

Kays

  • Hero Member
  • *****
  • Posts: 575
  • 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

 

TinyPortal © 2005-2018