procedure TForm1.btn1Click(Sender: TObject);
var
addr:DWORD;
begin
addr:=2;
if (not IsBadReadPtr(Pointer(addr),4)) then ShowMessage('1')
else ShowMessage('0');
end;
正常运行,肯定是ShowMessage('0')
但现在有个奇怪的问题,我拿到另一台电脑上去运行,会崩溃,有大神能指点下吗

解决方案 »

  1.   

    在你的电脑上Pointer(addr)有定义,但在另一台电脑上没有对addr进行定义或锁定了addr的资源,你一读就产生Exception了,严重的情况也就是你的崩溃了。
    也许这样试试:
    var 
      Bad:Boolean;
      addr:DWORD;
    begin
      addr:=2;
      try
        Bad:=IsBadReadPtr(Pointer(addr),4);
      except
        Bad:=False;
      end;
    if (not Bad ) then ShowMessage('1')
    else ShowMessage('0');
      

  2.   

    https://msdn.microsoft.com/zh-cn/visualc/aa366713%28v=vs.85%29该函数已经废弃,不该再使用,具体原因自己看res吧。