Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 05-20-2007, 12:08 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default PSafearray.

I am using a third-party DLL which has a function that takes PSafeArray type as a parameter. Here is my code:

[DELPHI].................................................. .........
var
Data : PSafeArray;
begin

oReader.Get_iSeADate(Data);[/DELPHI]

Now how to retrieve the array values of "Data" variable? I tried this but I got a compiling error:

Code:
Data[1].pvData;
Regards,
Abdulaziz Jasser
Reply With Quote
  #2  
Old 05-20-2007, 11:02 PM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,335
Default RE: PSafearray.

All is done through a variant, the PSafeArray isn't an array directly. The array is in the VArray.

Code:
var 
  arr: Variant;
  i: Integer;
begin
  TVarData(arr).VType := varOleStr OR varArray; 
  TVarData(arr).VPointer:= Data; 
  for i := VarArrayLowBound(arr, 1) to VarArrayHighBound(arr, 1) do 
    Showmessage(arr[I]); 
  Data := nil;
end;
Objective reality is a delirium caused by lack of alcohol in blood.
There is no place like 127.0.0.1
Reply With Quote
  #3  
Old 05-21-2007, 01:57 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default RE: PSafearray.

I got an error on the "Showmessage(arr[I]);". Do I have to do something with "Data: variable before passing it to the function that fill it with the data? I mean to I have to create it or initialize it? Also I am expecting integer values to filled in the "Data" variable. Does that make any difference? I am completely lost with PsafeArray. This is my first time to use it and I couldn’t find any help on the web.

Regards,
Abdulaziz Jasser
Reply With Quote
  #4  
Old 05-22-2007, 05:18 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default RE: PSafearray.

Thanks Norrit for trying to help. But I found the solution my self. I don't need to use a “Variant” variable to retrieve the data from the array. I found some useful Delphi's function in the ActiveX unit that deals with SafeArray type. Here is a sample of my code:

.................................................. .........
var
Data : PSafeArray;

i : Integer;

iLow, iHigh : Integer;

iValue : Integer;
begin
oReader.Get_iSeADate(Data);

SafeArrayGetLBound(Data,1,iLow);
SafeArrayGetUBound(Data,1,iHigh);

for i:=iLow to iHigh do begin
SafeArrayGetElement(Data,i,iValue);

Showmessage( IntToStr(iValue) );
end;


Regards,
Abdulaziz Jasser
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 03:12 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.