Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting a PSafeArray into a Array of Double?

Status
Not open for further replies.

kaywarner

Technical User
Jan 8, 2010
24
GB
Hi All, thanks for reading the post.

In my latest project, I'm trying to access a Method in a type library that requires a PSafeArray as one of its arguments (via COM interface).

Thus far, I have loaded a text file into an Array of doubles but now I am unable to pass it to the method.

the function i'm using is as below:

Function TForm1.BeamTempratureCalc (Periods: Integer): Double;
var
COM_Method_Data: PSafeArray; //to be sent to the method
Tmp: TempCalc;

begin
COM_Method_Data:=Addr(TempArray); //TempArray is an array of double
COM_Method_Data:=SafeArrayCreateVector(vt_R8,0,Periods);
COM_Method_Data.pvdata:=@COM_Method_Data;
Tmp:=coTempCalc.create;
BeamTempratureCalc:=Tmp.RateOfChange(COM_Method_Data,Periods);

Does anyone have any experience or advice for this kind of problem?

many thanks, Kay
 
For one COM interface I work with it wants an array (not sure it is a PSafeArray) but here's the code.

Code:
var
    va: OLEVariant;
begin

 va := VarArrayCreate([0,5],varVariant); //array of variants
 va[0] := Detail.View;
 va[1] := EmptyParam;
 va[2] := DetailComment.View;
 va[3] := PaymentSchedule.View;
 va[4] := DetailComment.View;
 va[5] := HeaderOptFld.View;

 ComObject.Compose(va);
 
Thanks for that DjangMan, thats really great.

Am i correct in thinking that you populate a OLEVarient with the information (in my case that would be an array of doubles), then when you use;

ComObject.Compose(va)

that converts the OLEVarient into a PSafeArray?

thanks, Kay

 
No - the .Compose method is specific to the COM object that I'm using.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top