Solved

How to resolve PSafeArray from dll

Posted on 2006-11-17
5
360 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 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

21 Experts available now in Live!

Get 1:1 Help Now