乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Delphi的"Invalid pointer operation"異常的解決辦法 - D...

       木子示羊 2010-09-10
      Delphi的"Invalid pointer operation"異常的解決辦法 收藏
          今天用Delphi編寫了個dll,用到了TStringList來傳遞多參數,如下:
          view plaincopy to clipboardprint?
      function DBM_SetParam(procName: string; paramValues: TStringList = nil): Boolean;stdcall;  
      var 
        i: integer;  
      begin 
        try 
          if (paramValues<>nil) then 
          begin 
            for i := 0 to paramValues.Count - 1 do 
            begin 
              GParameters.AddParameter;  
              GParameters[i].Value := paramValues[i];  
            end;  
          end;  
          Result := True;  
        except on e: Exception do 
          begin 
            Result := False;  
          end;  
        end;  
      end; 
      function DBM_SetParam(procName: string; paramValues: TStringList = nil): Boolean;stdcall;
      var
        i: integer;
      begin
        try
          if (paramValues<>nil) then
          begin
            for i := 0 to paramValues.Count - 1 do
            begin
              GParameters.AddParameter;
              GParameters[i].Value := paramValues[i];
            end;
          end;
          Result := True;
        except on e: Exception do
          begin
            Result := False;
          end;
        end;
      end;
          然而在應用程序中調用的時候,卻出了點問題:整個運行過程是有效的,并且參數也都傳遞成功,但是當結束了該API函數執(zhí)行后每次都會彈出“Invalid pointer operation”的異常。調用代碼如下:
          view plaincopy to clipboardprint?
      procedure TForm1.Button3Click(Sender: TObject);  
      var 
        paramList: TStringList;  
      begin 
        paramList := TStringList.Create;  
        paramList.Add('2');  
        if (not DBM_SetParam('GetUserName', paramList)) then 
        begin 
          ShowMessage('Set parameters failed!');  
        end;  
          
      end; 
      procedure TForm1.Button3Click(Sender: TObject);
      var
        paramList: TStringList;
      begin
        paramList := TStringList.Create;
        paramList.Add('2');
        if (not DBM_SetParam('GetUserName', paramList)) then
        begin
          ShowMessage('Set parameters failed!');
        end;
       
      end;
          在google里搜索Invalid pointer value發(fā)現遇到同樣問題的同志也不在少數。順藤摸瓜,終于在Delphi聯(lián)機幫助里找到了下面的描述:
          On Windows, if a DLL exports routines that pass long strings or dynamic arrays as parameters or function results (whether directly or nested in records or objects), then the DLL and its client applications (or DLLs) must all use the ShareMem unit. The same is true if one application or DLL allocates memory with New or GetMem which is deallocated by a call to Dispose or FreeMem in another module. ShareMem should always be the first unit listed in any program or library uses clause where it occurs.
      ShareMem is the interface unit for the BORLANDMM.DLL memory manager, which allows modules to share dynamically allocated memory. BORLANDMM.DLL must be deployed with applications and DLLs that use ShareMem. When an application or DLL uses ShareMem, its memory manager is replaced by the memory manager in BORLANDMM.DLL.
      Note
      Linux uses glibc's malloc to manage shared memory.
          【2010-6-3:翻譯一下,供大家參考:
          Windows中如果一個動態(tài)庫導出函數以參數形式傳遞或者返回了一個長字符串或者動態(tài)數組(無論是直接傳遞還是包含在一個對象中),那么動態(tài)庫以及其調用程序都必須得引用ShareMem單元。同樣,如果程序或者庫通過New或者GetMem申請了內存,并且該內存在另一個模塊中通過Dispose或FreeMem釋放,也得這么做。務必把ShareMem放在程序或者庫所有引用單元之首。
      ShareMem是BORLANDMM.dll內存管理單元接口,它允許模塊間共享動態(tài)申請內存。BORLANDMM.dll必須與使用了改單元的程序或者Dll一塊兒部署。當程序或者動態(tài)庫使用了ShareMem,其內存管理將會由BORLANDMM.dll接管。
      注意:
      Linux下使用glibc的malloc來管理共享內存?!?/div>
          上述問題僅在windows里才有啊,呵呵,于是在dll里把Uses子句的top 1增加ShareMem引用,另外在應用程序的Project域的Uses子句第一個引用也加上ShareMem。最后編譯,運行,沒有看到哪個煩人的異常提示了:P
       
      本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/derryzhang/archive/2009/08/05/4412436.aspx

        本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現有害或侵權內容,請點擊一鍵舉報。
        轉藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多