procedure TForm3.btnQueryClick(Sender: TObject);
var
  szDecryptString,szTQueryString: string;
  temp:Integer;
begin
  szTQueryString := 'select SoftWare_ID,name from Software';
      Form1.adoquery2.SQL.Clear;
      Form1.adoquery2.SQL.Add(szTQueryString);
      Form1.adoquery2.Open;
      szDecryptString:=Form1.adoquery2.Fields[1].AsString;
//        szDecryptString:=Form1.Decrypt(szDecryptString,true);//A句
        temp:=Form1.adoquery2.Fields[0].AsInteger;///如果把上一句(A句起用。就会出现
                  // Access violaiton At Address 0xXXX in module. 错误.
     exit;
end;
/////////////////////////////////////////////
function TForm1.Encrypt(Src: string; bMode: boolean): string;
var
  hDLl: THandle;
  myDecrytFiled: Decryt;
  ucInData: array[1..32] of UCHAR;
  ucOutData: array[1..32] of UCHAR;
  i, inLen, outLen: Integer;
  szReult, Temp: string;
begin
   inLen := Length(Src);
  if bMode = true then
  begin
    inLen := trunc(inLen / 2);
    for i := 1 to inLen do
    begin
      Temp := MidStr(Src, i * 2 - 1, 2);
      ucInData[i] := strtoint('$' + Temp);
    end;
  end
  else
    CopyMemory(@ucInData[1], @Src[1], inLen);
     for i:=inLen+1 to 31 do
   ucInData[i]:=0;
      for i:=1 to 32 do
   ucOutData[i]:=0;
  outLen := trunc((InLen + 7) / 8) * 8;
 anblue(@ucOutData,@ucInData,inLen,bMode);///这个调用一个VC的DLL。
    Result := '';
    for i := 1 to OutLen do
      case bMode of
        false: Result := Result + inttohex(ucOutData[i], 2);
        true: Result := Result + chr(ucOutData[i]);
      end;
end;
谁能解释这是为什么?

解决方案 »

  1.   

    把 temp:=Form1.adoquery2.Fields[0].AsInteger;这句改成showmessage('hello')报错吗?
    我怀疑form1.Encrypt方法报错,但delphi调试器把错误指向下一句了
      

  2.   

    当然错了, 你看看,调用的函数名称都不一致!
    szDecryptString:=Form1.Decrypt(szDecryptString,true);//A句
                       ============
    function TForm1.Encrypt(Src: string; bMode: boolean): string
                   =========
      

  3.   

    delphi没有那么多的bug,花点时间检查自己的代码吧
      

  4.   

    谢谢大家!
    那个函数我贴错了。并且函数错不会出现这样的问题吧!
    在程序中有数十个地方都调用这个加解密函数,就在这个form3出现问题,其它form调用这个
    函数没有任何问题。
    TO NightCloud():
    Form1.adoquery2.Open;
    szDecryptString:=Form1.adoquery2.Fields[1].AsString;
    szDecryptString:=Form1.Decrypt(szDecryptString,true);
     showMessage(Form1.adoquery2.Fields[1].AsString);
    并且我已经用F7跟踪进入,在执行完加解密函数,还不报错。
    只要对Form1.AdoQuery2进行取值就会出现AV错误。
    哪个热心人能够帮帮忙?
      

  5.   

    把 szDecryptString:=Form1.Decrypt(szDecryptString,true);
    放到 temp:=Form1.adoquery2.Fields[0].AsInteger;后面呢?会不会报错?
      

  6.   

    TO NightCloud():
      这个当然不会报错了。谁能说出来原因来。我再开贴给分
      

  7.   

    你检查一下:
    szDecryptString:=Form1.adoquery2.Fields[1].AsString;
    是否为空则第一:如果为空 不要加密直接放入数据库,
    if trim (aStr) <> ''  then
      Form1.adoquery2.Fields[1].AsString := Encrypt(aStr)
    else
      Form1.adoquery2.Fields[1].AsString := aStr;  第二:如果为空 不要解密。if trim (Form1.adoquery2.Fields[1].AsString ) <> ''  then
      aStr := Decrypt(Form1.adoquery2.Fields[1].AsString)else
      aStr := Form1.adoquery2.Fields[1].AsString := aStr;修改后把数据库中的全部清空一下,因为原来为空加密得解不出来