NoShow/EndNoShow block causes crash

If I put this snippet inside a NoShow/EndNoShow block, Panorama X crashes.

looparray HiddenFieldsArray,cr(),ArrayElement
    field (ArrayElement)
    deletefield
endloop

Can anybody replicate this?

It shouldn’t crash (I didn’t test it), but your code shouldn’t work either. There should be an error when the field statement is run. You can’t set the current field to a hidden field, that is not allowed. Are you saying it does work if not used in a NoShow/EndNoShow block? That would really surprise me.

Yep, this produces a lovely crosstab:
NoShow

;  Delete unwanted fields and ensure the key fields are in the desired order

execute {showthesefields } + quoted(CatFields) + {+cr()+} + quoted(CatNames) + {+cr()+} + quoted(CatTabs)

HiddenFieldsArray = hiddenfields()
showallfields
                                                                                EndNoShow


;  I can't put this next block of code inside a NoShow/EndNoShow block or Panorama X  crash    ****************************************

looparray HiddenFieldsArray,cr(),ArrayElement
    field (ArrayElement)
    deletefield
endloop

My original code had an old-fashioned loop structure and that worked also.

That’s why it worked. You weren’t setting the current field to a hidden field, because after the showallfields, there were no hidden fields.

Rather than loading all the hidden fields at one time you can simply add one at a time and delete it instantly in your looparray.

looparray HiddenFieldsArray,cr(),ArrayElement
    showthesefields visiblefields()+cr()+ArrayElement
    field (ArrayElement)
    deletefield
endloop

This will minimize the amount of screen real estate needed and only show an additional field briefly flashing on and disappearing. The noshow and endnoshow certainly do cause problems. I tried surrounding this code with noshow/endnoshow and it seemed to work until I clicked on the Show All fields in the Field menu and got an error message {datatype( function error: no field or variable named “”.}. After that if I tried to insert a couple of new fields Panorama would crash.

All true but I come back to my question - why does the loop cause a crash inside a NoShow/EndNoShow block?

Guess I didn’t make it clear – this is probably a bug in the field statement, or possibly in the deletefield statement. One of those doesn’t like it if you specify a hidden field.

But the fields are not hidden - as Dave pointed out, I preceded the loop with a showallfields statement. It may just be my gremlin-affected Mac which is why I asked if anybody can replicate the behaviour.

But if you have used noshow, then the showallfields statement doesn’t actually do anything, so the fields remain hidden.

Well, that’s tricky - I had assumed that, after a NoShow, everything happened as instructed, I just didn’t get to see it happen. Now it seems that at least one statement doesn’t actually get implemented. Are there others in that category - maybe everything with a show operation?

Anything that involves display doesn’t happen. showallfields does nothing except change the display, so if noshow is in effect, it does nothing.

Of course it still shouldn’t crash, it should realize that the field is hidden and stop the procedure with an error message.

This doesn’t cause a crash - does that help to find the cause?

HiddenFieldsArray = hiddenfields()
showallfields
                                      NoShow

looparray HiddenFieldsArray,cr(),ArrayElement
    field (ArrayElement)
    deletefield
endloop

I don’t think finding the cause of the crash will be difficult. In fact, I probably won’t bother, I’ll just make sure that the affected statements check to make sure that a hidden field isn’t involved, then issue an error message instead of attempting the operation. I’ve filed Bitbucket issue #725 for this problem.

I think you may be imagining that the problem will be fixed and you’ll be able to write the code the way you had originally planned. You won’t be able to do that – the code with noshow still won’t work, but it will stop with an error message instead of the error message being a crash. But I’m not planning to make a change to allow hidden fields to be manipulated without making them visible first.

I might consider a statement to delete all hidden fields, but that would be a pretty low priority item.