SalArraySetUpperBound( ) anomolous behaviour, especially with UDVs

forum.gupta.bugreport (2005-2010)
James McCall

SalArraySetUpperBound( ) anomolous behaviour, especially with UDVs

Post by James McCall » 04 Dec 2007, 00:05

 Posted by:  James McCall 

Mirko,

Thanks for checking it out on 4.2

For your info ... I used arrays based at 1 as a work-around for another
"coding challenge" presented by TD. For 0 based arrays,
SalArrayGetUpperBound( ) will return TRUE and report 0 as the upper bound
for empty arrays rather than returning FALSE and/or giving the upper bound
as -1. See attached sample, also in CTD2000 - I doubt it will ever be fixed
because it will probably break a lot of working code.

So my choice was to use 0 based arrays and code If SalArrayIsEmpty( ) to
know if it is empty or use 1 based arrays and get the correct answer from
SalArrayGetUpperBound( ). I took the second option because:
a) I thought it would be less messy in the code
b) Where I use an instance var (Number: nItemCount) it is always set to the
correct value, no need to initialise to -1 and no need to subtract 1 when
setting the upper bound.

Ironic that my decision to avoid coding If SalArrayIsEmpty( ) now needs
another work-around which calls that very function. My code tends to look
like this now ...

! Call SalArraySetUpperBound( refaItemInfo, 1, -1 ) ! this crashes the
application
! Call SalArraySetUpperBound( refaItemInfo, 1, 0 ) ! this won't do
anything
If ( NOT SalArrayIsEmpty( refaItemInfo ) )
Call SalArraySetUpperBound( refaItemInfo, 1, 1 ) ! cut it down to
one element, not possible to empty it

This is the story of my life with TD.

While we are on the subject there is also a bug in VisArrayFillxxx( )
functions, which I think I reported in the newsgroups before. You have to
add 1 to the number of elements you want filled if the array is based 1
(probably need to add 2 if it is based 2).
eg. Call VisArrayFillNumber( naSelectedItemID, 0xFFFF, nItemCount + 1 )

I was once asked if I wanted to use an automatic porting service to change
my TD code to .NET and my answer was "so much of my code is kludge,
work-arounds and direct calls to the Windows API, why would I want to port
all that junk"?

James

Attachment: SalArrayGetUpperBoundForEmtpyArrays.apt

Mirko
Italy
Posts: 981
Joined: 04 Apr 2017, 08:56
Location: Geneva

SalArraySetUpperBound( ) anomolous behaviour, especially with UDVs

Post by Mirko » 04 Dec 2007, 08:34

 Posted by:  Mirko BONANNO 

Yes , you are right,

I do protect my SalArrayGetUpper by a If NOT SalArrayIsEmpty...

lol
Mirko

Return to “gupta.bugreport”

Who is online

Users browsing this forum: [Ccbot] and 0 guests