【问题标题】:How to get data from a multidimensional PSafeArray?如何从多维 PSafeArray 中获取数据?
【发布时间】:2012-10-27 05:01:34
【问题描述】:

我需要从 Delphi 中的 PSafeArray 读取数据。
PSafeArray 由在 C# 开发的 DLL 中实现的方法返回。该方法返回一个二维字符串数组string[,]。如何在 Delphi 中读取 PSafeArray 这样的结果?

【问题讨论】:

    标签: c# delphi delphi-7 safearray


    【解决方案1】:

    您必须使用SafeArrayGetLBoundSafeArrayGetUBoundSafeArrayGetElement 函数。

    试试这个示例

    var
      LSafeArray: PSafeArray;
      LBound, UBound, I: LongInt;
      LYBound, UYBound, J: LongInt;
      Index: array [0..1] of Integer;
      LData: OleVariant;
    begin
      //get the PSafeArray
      LSafeArray := GetArray;// GetArray is your own function
      //get the bounds of the first dimension
      SafeArrayGetLBound(LSafeArray, 1, LBound);
      SafeArrayGetUBound(LSafeArray, 1, UBound);
      //get the bounds of the second dimension
      SafeArrayGetLBound(LSafeArray, 2, LYBound);
      SafeArrayGetUBound(LSafeArray, 2, UYBound);
    
      //iterate over the array  
      for I := LBound to UBound do
       for J := LYBound to UYBound do
        begin
          //set the index of the element to get
          Index[0]:=I; 
          Index[1]:=J;
          SafeArrayGetElement(LSafeArray, Index, LData);
    
          //do something with the data  
          Memo1.Lines.Add(LData);
        end;
      SafeArrayDestroy(LSafeArray);
    end;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-21
      • 2014-09-20
      • 2021-08-07
      • 2019-11-04
      • 2016-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多