簡體   English   中英

Javascript Com數組組件給我錯誤的數組值

[英]Javascript Com array Component giving me wrong array values

我嘗試為C#方法創建COM組件,然后嘗試使用javascript訪問此方法。

我已經運行GACUtil -i和Regasm / Codebase命令來創建共享程序集,並且還成功注冊到注冊表中。 這是我的C#方法,為此它返回一個int []數組,為此方法我創建了一個COM組件。 nChannelsCount = 15 ,用於for循環

[Guid("4794D615-BE51-4a1e-B1BA-453F6E9337C4")]  
  [ComVisible(true)]   
 [ClassInterface(ClassInterfaceType.None)]  
  [ComSourceInterfaces(typeof(IComOjbect))] 
   public class MyComObject : IComOjbect 
   {

在此處輸入圖片說明
}

   [Guid("4B3AE7D8-FB6A-4558-8A96-BF82B54F329C")] 
   [ComVisible(true)]   
 public interface IComOjbect    
    {       
    [DispId(0x10000009)]    
        int[] GetData(int index);   
     }

但是,當我在javascript中訪問此方法時,它給了我15個計數,但我想在“快速監視”中顯示5500個計數。 我不知道如何在javascript中做到這一點,但是我仍然嘗試使用以下javascript代碼

<html>   
<head>   
<title>My Com Component</title>  
<object id="myComComponent" name="myComComponent" classid="clsid:4794D615-BE51-4A1E-B1BA-453F6E9337C4">
</object> 
<script language="javascript" type="text/javascript">        
function MyComComponent_onload() 
    {              
      try {  
           var nAllData = [];   
           for (var index = 0; index < 15; index++) 
             {

               nAllData.push(myComComponent.GetData(index));  
              } 
            alert(nAllData.length);  
          }             
      catch (err) {             
        alert(err.message);    
       }           
  }   
</script> 
</head>  
<body onload="MyComComponent_onload();" onunload="MyComComponent_onunload();"> 
</body>   
</html>

GetData返回一個數組。 JavaScript代碼將其調用15次,並且每次將結果壓入另一個數組nAllData (JavaScript中的變量名與C#中的變量名無關緊要-它們是不相關的)。 結果,您有一個由15個元素組成的數組,其中每個元素又是一個數組(大概是5500個元素-無論GetData返回什么)。

GetData實現中的循環是沒有意義的-函數在該循環的第一次迭代中返回。 目前尚不清楚您要達到的目標。

最后,我不相信JavaScript可以直接使用safearrays(這就是我認為GetData的返回值最終由COM interop表示的方式)。 嘗試這個:

var data = new VBArray(myComComponent.GetData(index)).toArray();
alert(data.length);
nAllData.push(data);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM