Lazarus

Free Pascal => General => Topic started by: SunyD on March 15, 2017, 10:31:49 pm

Title: How can I catch this Error or check to nil?
Post by: SunyD 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?

Title: Re: How can I catch this Error or check to nil?
Post by: ASerge on March 15, 2017, 10:44:50 pm
...or check to nil?
Code: Pascal  [Select][+][-]
  1. if aBuffer <> nil then
Title: Re: How can I catch this Error or check to nil?
Post by: SunyD on March 15, 2017, 10:55:59 pm
Thanks, so easy I didn't see it  :-[
Title: Re: How can I catch this Error or check to nil?
Post by: Ñuño_Martínez 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.
Title: Re: How can I catch this Error or check to nil?
Post by: Kays 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
TinyPortal © 2005-2018