Solved

How to resolve PSafeArray from dll

Posted on 2006-11-17
5
364 Views
Last Modified: 2010-04-04
I have a dll wrapping a webservice call (C#.net).  
When I import the library to Delphi, the return type changes to PSafeArray.

Here's the signature from the TLB:
    procedure GetNumberRange(const connString: WideString; const nameCaller: WideString;
                             identCaller: Integer; const orderRef: WideString; countryCode: Word;
                             quantity: LongWord; oneRange: WordBool; numbers: PSafeArray); safecall;
Here's my call from Delphi (Same as an exmple I got here):
  a:  Variant;
begin
  bnds[0].LowBound := 0;
  bnds[0].ElementCount := 0;
  ws := CoResETag.Create();
  psa := SafeArrayCreate(varOLEStr,1,bnds);
 try
    ws.GetNumberRange(tbConnString.Text,tbNameCaller.Text,StrToInt(tbIdentCaller.Text),tbOrderRef.Text,     StrToInt(tbCountryCode.Text), StrToInt(tbQuantity.Text), true, psa);
/****/
I get:  Specified array was not of the expecting type  when executing this.
Help please
0
Comment
Question by:jlaurin
  • 2
5 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 17978325
try this

var bound: TSafeArrayBound;
    sa: PSafeArray;

bound.lLbound := 0;
bound.cElements := 5;
sa := SafeArrayCreate(varVariant, 1, bound);

ziolko.
0
 

Author Comment

by:jlaurin
ID: 17979192
Nope.  Still getting the same error.
0
 
LVL 21

Accepted Solution

by:
ziolko earned 500 total points
ID: 17979870
var var_array: Variant;

var_array := VarArrayCreate([0,0], varVariant);
and then use var_array instead of psa
-or-
var var_array: Variant;
     lck: Pointer;

var_array := VarArrayCreate([0,0], varVariant);
lck := VarArrayLock(var_array);
and use: lck (dont forget to call VarArrayUnlock)

ziolko.
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21133158
Forced accept.

Computer101
EE Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi application Soap connection 5 96
Delphi Form ownership 4 72
Press three keys together and trigger a function 3 50
Firemonkey android show image from resource ? 1 32
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now