Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8409093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:48:44+00:00 2026-06-09T23:48:44+00:00

I have a procedure that I need to call using COM, which is declared

  • 0

I have a procedure that I need to call using COM, which is declared like this in C#:

public string ali(int[] num)
{
    string r;
    r ="";
    foreach (int a in num)
    {
        r = r + Convert.ToString(a) + ";";   
    }
    return r;
}

The Delphi declaration in the imported TypeLibrary is:

function TSqr.ali(num: PSafeArray): WideString;
begin
  Result := DefaultInterface.ali(num);
end;

I have this code to convert integer Array into a PSafeArray:

Function ArrayToSafeArray2 (DataArray: array of integer):PSafeArray;
var
  SafeArray: PSafeArray;
  InDataLength,i: Integer;
  vaInMatrix: Variant;
begin
  InDataLength := Length(DataArray);
  vaInMatrix := VarArrayCreate([Low(DataArray), High(DataArray)], varInteger);
  for i:= Low(DataArray) to High(DataArray) do
  begin
    vaInMatrix[I] :=  DataArray[I];
  end;
  SafeArray := PSafeArray(TVarData(vaInMatrix).VArray);
  Result := SafeArray;
  VarClear(vaInMatrix);
  SafeArrayDestroy(SafeArray);
end;

and this code to call my COM function

var
  a:array of integer;
  Answer:String;
begin
  SetLength(a,3);

  a[0] := 1;
  a[1] := 2;
  a[2] := 2;

  Answer := Sqr1.ali(ArrayToSafeArray2(a));
  ShowMessage(Answer);
end;

but error ocure:

” EOLeExeption with message ‘SafeArray of rank 0 has been passed to method expecting an array of rank 1’ …”

what i should be do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:48:45+00:00Added an answer on June 9, 2026 at 11:48 pm

    Your conversion routine is destroying the SafeArray before the caller can use it. Unlike Delphi arrays, COM arrays are not reference counted. Don’t destroy the SafeArray until after you have passed it to the COM procedure, eg:

    function ArrayToSafeArray2 (DataArray: array of integer): Variant;
    var
      i: Integer;
    begin
      Result := VarArrayCreate([Low(DataArray), High(DataArray)], varInteger);
      for i:= Low(DataArray) to High(DataArray) do
      begin
        Result[I] := DataArray[I];
      end;
    end;
    

    .

    var
      a:array of integer;
      v: Variant;
      Answer:String;
    begin
      SetLength(a,3);
    
      a[0] := 1;
      a[1] := 2;
      a[2] := 2;
    
      v := ArrayToSafeArray2(a);
    
      Answer := Sqr1.ali(TVarData(v).VArray);
      ShowMessage(Answer);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to call a stored procedure using JPA and found this article: http://www.oracle.com/technology/pub/articles/vasiliev-jpql.html
I have an existing stored procedure in SQL Server that I need to call
I have this procedure that executes another procedure passed by a parameter and its
I have this stored procedure that I want to use for my SAP crystal
I have a stored procedure that has this line: SET @SQL = 'SELECT path,title,tags
It looks like #temptables created using dynamic SQL via the EXECUTE string method have
I have created a method that can be called using a stored procedure name
I am using Java + iBatis and have a need to call an Oracle
I have a SSRS report that need 2 parameters ... I need to call
I have a stored procedure that returns a valueI call it from other stored

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.