DynArray.Contains vs. try onfail

21 views
Skip to first unread message

Jure Zorko

unread,
Sep 17, 2024, 5:46:34 AMSep 17
to TheDBCommunity
If I use try ... onFail to check whether element exists in DynArray, then paradox
automatically creates this element in array with value "N/A"
Is this normal?

Short script to show you, what I mean:

method run(var eventInfo Event)
var DA DynArray[] AnyType
    tmp smallint
endVar
DA["x"] = "x"
view(DA)   ; I see only "x" element

try
tmp = DA["does not exist"]
   onFail
    tmp = 0
   endTry

   view(DA)  ; now I have 2 elements in array "x" and "does not exist"
endMethod

I had to change  code to
  if DA.Contains("does not exist") then
tmp = DA["does not exist"]
   else
    tmp = 0
   endIf

I had problems, because I send this DA to other methods, which use element "does not exist", and now it has a not-defined value.

Jure

Mark Bannister

unread,
Sep 17, 2024, 10:56:36 AMSep 17
to TheDBCommunity
Yes, pain in the butt.  I use these methods

{
                              IsAssigned    NOT Blank or Zero
 cmIsDynArrayItem               *               *
 cmIsDynArrayItemHasValue        *               *
 cmIsDynArrayItemisAssigned      *

}
method cmIsDynArrayItemisAssigned(stKey string, var myar dynarattype ) logical
var
  lort logical
endvar

lort = False
if myar.size() > 0 then
   if myar.contains( stkey ) then
      lort = ( myar[ stkey ]. isassigned() )
  endif
endif
return lort
endMethod

---------------------------------------------------------
{
                              IsAssigned    NOT Blank or Zero
 cmIsDynArrayItem               *               *
 cmIsDynArrayItemHasValue        *               *
 cmIsDynArrayItemisAssigned      *

}

;// is array item assigned and not blank
method cmIsDynArrayItemHasValue(stKey string, var myar dynarattype ) logical
var
  lort logical
endvar

lort = False
if cmIsDynArrayItemisAssigned(stkey, myar )  then
           ;// confusing but we are asking is is NOT blank
           lort =  NOT cmIsBlank( myar[ stkey ]   )
     
endif

return lort
endMethod


--------------------------------------------------------
{
                              IsAssigned    NOT Blank or Zero
 cmIsDynArrayItem               *               *
 cmIsDynArrayItemHasValue        *               *
 cmIsDynArrayItemisAssigned      *

}
;;
;;// return true if array item is assigned and NOT blank or zero
method cmIsDynArrayItem(stKey string, var myar dynarattype ) logical
var
  lort logical
endvar

Steven Green

unread,
Sep 17, 2024, 3:16:03 PMSep 17
to thedbco...@googlegroups.com

tmp = DA["does not exist"]

yes, that creates the element.. how about this instead

if da.contains then tmp =1 else tmp =0

Steve at Oasis Trading Post

--
You received this message because you are subscribed to the Google Groups "TheDBCommunity" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thedbcommunit...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/thedbcommunity/6f27b4b1-969d-49b9-8604-c9f5ce97b9a5n%40googlegroups.com.

Jure Zorko

unread,
Sep 17, 2024, 3:18:09 PMSep 17
to TheDBCommunity


how about this instead

if da.contains then tmp =1 else tmp =0

Yes, I did exactly that. 
Reply all
Reply to author
Forward
0 new messages