procedure TForm1.ReadUser;
var
x1,l:integer;
ll_resp: pchar;
str:string;
begin
//读二进制版本文件 判断是否是用户卡
    ll_resp:=StrAlloc(255);
    l:=INF_read_file(ll,09,3,ll_resp);//读     
    str:=copy(ll_resp,3,2) ;
    if str<>'01' then
    begin
  Application.MessageBox('不是用户卡','信息提示',MB_APPLMODAL or MB_ICONINFORMATION or MB_OK) ;
   exit;
    end;
    //读卡片内容       Application
    x1:=INF_read_file(ll,04,32,ll_resp);   //读
    str:=ll_resp;
    le_number.Text:=copy(str,125,10);
    Application.MessageBox('读卡成功','信息提示',MB_APPLMODAL or MB_ICONINFORMATION or MB_OK) ;
    INF_close(ll);
    strdispose(ll_resp);end;其中INF_read_file();这是调用的一个函授 其中参数ll_resp 是指针Pchar 类型 函授返回的是Integer 类型的 。当我运行到读卡成功的时候。出现如图形式的错误 : x1:=INF_read_file(ll,04,32,ll_resp); 
  INF_close(ll); 
  strdispose(ll_resp); //这一步报错 ---错误如下:工程prject.exe 检测到错误类EInvalidPointer,错误信息:‘Invalid pointer operation’.进程中止 使用单步调试或继续运行。 但是不知如何解决 请大哥大姐们指点一下。标注一下我是delphi 初学者。

解决方案 »

  1.   

    procedure TForm1.ReadUser;
    var
    x1,l:integer;
    ll_resp: pchar;
    str:string;
    begin
    //读二进制版本文件 判断是否是用户卡
        ll_resp:=StrAlloc(255);  //去掉这行看看
        l:=INF_read_file(ll,09,3,ll_resp);//读     
        str:=copy(ll_resp,3,2) ;
        if str<>'01' then
        begin
      Application.MessageBox('不是用户卡','信息提示',MB_APPLMODAL or MB_ICONINFORMATION or MB_OK) ;
       exit;
        end;
      

  2.   

    这样  肯定不行  INF_read_file()中ll_resp 的方法是指针的形式传过来的。 就会出现检测到错误类EAccessviolation    
      

  3.   

    INF_read_file(ll,04,32,ll_resp); 这个方法中是否已经把ll_resp给释放了。
      

  4.   

    INF_read_file(ll,04,32,ll_resp)  ll_resp传过来的时候就是一个指针类型 
      

  5.   

    procedure TForm1.ReadUser;
    var
    x1,l:integer;
    ll_resp: pchar;
    str:string;
    begin
    //读二进制版本文件 判断是否是用户卡
        ll_resp:=StrAlloc(255);
        l:=INF_read_file(ll,09,3,ll_resp);//读     
        str:=copy(ll_resp,3,2) ;
        if str<>'01' then
        begin
      Application.MessageBox('不是用户卡','信息提示',MB_APPLMODAL or MB_ICONINFORMATION or MB_OK) ;
       exit; //这种写法不安全,ll_resp有可能不被释放
        end;
        //读卡片内容       Application
        x1:=INF_read_file(ll,04,32,ll_resp);   //读
        str:=ll_resp;  //这有可能导致问题,掉试试会不会出错 
        le_number.Text:=copy(str,125,10);
        Application.MessageBox('读卡成功','信息提示',MB_APPLMODAL or MB_ICONINFORMATION or MB_OK) ;
        INF_close(ll);
        strdispose(ll_resp);end;
      

  6.   

    还有一种方法,你把ll_resp定义成Char数组,这样就不能分配和释放内存了。