How to convert a safeArray ?

Discussions related to Visual Prolog
User avatar
Tonton Luc
VIP Member
Posts: 814
Joined: 16 Oct 2001 23:01

How to convert a safeArray ?

Unread post by Tonton Luc » 15 Jan 2018 16:57

Hi,

When I recover the Range value in a Excel sheet Range("B6:E8") using comDispInterface::getProperty, I obtein a comDomains::safeArray variant.
How to convert it in string_list (or integer_list) ?

User avatar
Thomas Linder Puls
VIP Member
Posts: 2447
Joined: 28 Feb 2000 0:01

Re: How to convert a safeArray ?

Unread post by Thomas Linder Puls » 15 Jan 2018 22:29

There are classes: safeArrayBstr and safeArrayInteger. With constructors newCopy that takes a nativeSafeArray as argument. They will raise an exception if the type does not match.

On such an object, you can call getBoundaries to obtain a description of the indices and their range.

And then you can obtain individual elements using getValue (and set them using setValue).

Notice that you are responsible for destroying the array:

Code: Select all

predicates     safeArrayDestroy : (comDomains::nativeSafeArray SafeArray).     % @short See SafeArrayDestroy in MSDN     % @end   predicates     safeArrayDestroyData : (comDomains::nativeSafeArray SafeArray).     % @short     % @short See SafeArrayDestroyData in MSDN     % @end   predicates     safeArrayDestroyDescriptor : (comDomains::nativeSafeArray SafeArray).     % @short See SafeArrayDestroyDescriptor in MSDN     % @end
I believe you have to use the first since you must destroy both the descriptor and the data.
Regards Thomas Linder Puls
PDC

User avatar
Tonton Luc
VIP Member
Posts: 814
Joined: 16 Oct 2001 23:01

Re: How to convert a safeArray ?

Unread post by Tonton Luc » 16 Jan 2018 10:29

Thanks for your help.
My code work fine now :

Code: Select all

            % with Selection = "D4:F6"             Values == Selection:getProperty("Value"),             if Values = comDomains::safeArray(SA) then                 Array = safeArrayVariant::newCopy(SA),                 Nb_array = Array:getBoundaries(), % [boundary(2,1),boundary(2,1)]                 Prem = Array:getValue([3,3]), % return cell F6 value                 _R_sa_destroy = safeArray_native::safeArrayDestroy(SA)             end if,
:D

Post Reply