Hmmm - maybe I'm missing something, but ....
Can't you use the feature of "using a numeric-indexed array as key" ?
(AFAIK it's an undocumented feature, except in the original release
notes for 5.x, which are no longer on the downloads site, and which I
can't find my copy of - so if anyone has them, could they re-post
somewhere. This feature allows you to use a numeric-indexed array as a
key, equivalent to presenting a set of keys:
put "a,b,c" into tA
split tA by comma
-- now we have tA[1]="a", tA[2]="b", tA[3]="c"
put "def" into tArray[tA]
-- now tArray["a"]["b"]["c"] = "def"
So, where Brian's code does
put the hilitedElement of the target into tElement
put 0 into tIndex
repeat for each item tItem in tElement
add 1 to tIndex
put tItem into tReference[tIndex]
end repeat
set the htmltext of field "ItemText" to tArray[tReference]
that should be equivalent to
put the hilitedElement of the target into tElement
split tElement by comma
set the htmltext of field "ItemText" to tArray[tElement]
Alex.
P.S. I also apologise for not looking at this earlier; I saw an earlier
email and thought to myself "Hmmm. I bet that's a case for that weird
array feature :-), and went looking for my copy of the release notes;
when I failed to find them, I forgot to look further into it.
On 21/12/2021 15:19, Brian Milby via use-livecode wrote:
I saw this originally and meant to dig a bit. Sorry for causing additional
work for you. Here is a widget script that does pretty much what you are doing
but leverages a way of array access that isn’t obvious.
https://github.com/bwmilby/DocEditorPlus/blob/master/DocEditorPlus_Scripts/stack_DocEditorPlus_widget_id_1008.livecodescript
You should not need to use a case statement. In my case the value was HTML in
one case but plain text otherwise.
It is part of a more involved stack, but the card with this widget may be
helpful for your purposes.
Thanks,
Brian
Sent from my iPhone
On Dec 21, 2021, at 6:38 AM, Keith Clarke via
use-livecode<[email protected]> wrote:
Hi folks,
For future reference, below is how I managed to get this sorted. The solution
seems rather ugly, but it works for the fixed depth of Tree View data I’m
interested in.
The root cause seems to be down to the way LiveCode handles array keys passed in
from variables. It doesn't seem possible to define a complete multidimensional
array in as a text string (as one might build URLs with parameters). Rather,
variables seem to be recognised and processed only if passed in for each individual
array key, within its square brackets. Furthermore, the square brackets seem to
need to be present in the markup of the array access call - hence the ugly switch
statement with explicit cases for each level of Tree View depth rather than
something more dynamic & generic...
on hiliteChanged
put the arrayData of control "Tree" into tTreeData
put the hilitedElement of control "Tree" into tHilitedElement
// Identify element depth
put the number of items in tHilitedElement into tDepth
put 0 into tLevelCount
repeat for each item tKey in tHilitedElement
add 1 to tLevelCount
put tKey into tLevel[tLevelCount]
put "[tLevel[" & tLevelCount & "]]" after tElement
end repeat
// Build array key to show element value in field
switch tDepth
case 1
put tTreeData[tLevel[1]] into field "Test"
break
case 2
put tTreeData[tLevel[1]][tLevel[2]] into field "Test"
break
case 3
put tTreeData[tLevel[1]][tLevel[2]][tLevel[3]] into field "Test"
break
end switch
end hiliteChanged
I’m sure the experienced developers here would find cleaner ways to achieve
this but this hack works and I can get back to evaluating the data accessible
from the PDF widget! :)
Best,
Keith
On 20 Dec 2021, at 21:13, Keith Clarke via
use-livecode<[email protected]> wrote:
I’m using the Tree View widget to provide a quick and dirty read-only display
of the various arrays of information that can be extracted from the PDF Widget.
Each PDF page contains too much text to read & understand within the constraints of
a single line in a Tree View control. So, on highlighting an element in the Tree View,
I want to display its value - such as arrayData[“Pages”][“1”][“text”] - into a field to
read the detail extracted. (Currently I’m putting it into the message box as an interim
step, as I tend to build & debug my scripts line by line and this is as far as I’ve
got!)
I may have misread the docs but it seems that when a Tree View element is
hilited, one doesn’t get immediate access to the element’s value. Instead, one
has to jump through hoops, by handling the hilitedElement, which returns the
nested keys of the element. So, I’m simply trying to convert this
comma-separated list to an array reference, so that I can get the value
associated with this key.
If I’ve missed a simple means to access the Tree View element’s value directly
‘on click', I’ll gladly change course!
Best,
Keith
On 20 Dec 2021, at 20:46, J. Landman Gay via
use-livecode<[email protected]> wrote:
I'm confused about what the goal is. The hilitedElement contains the text of
the selection. The array is already in place, so you don't really need to add
to it.
The reason you're seeing text in the message box is because the last line contains an unspecified
"put". Without a destination for the "put" it will go automatically to the
message box. If you want to work with it, you'd need to put the value into a variable.
What's the purpose of the concatenation, and what do you want to do with the
selection?
On 12/20/21 11:11 AM, Keith Clarke via use-livecode wrote:
Hi folks,
I’m struggling to access the value from a Tree View widget’s data array as the
hilitedElement changes - though I think my issue is more about working with
arrays than the Tree View widget.
The following test script (on the Tree widget) successfully gets the Tree’s
arrayData into tTreeData and creates a ‘correct-looking’ nested array key
syntax for any changing tHilitedElement.
However, the last line displays the tHilitedElement variable string in the
message box rather than concatenating it to tTreeData as the nested key to
return the element’s value.
on hiliteChanged
put the hilitedElement of me into tHilitedElement
if char -1 of tHilitedElement is comma then delete char -1 of tHilitedElement
replace comma with quote & "][" & quote in tHilitedElement
put "[" & quote before tHilitedElement
put quote & "]" after tHilitedElement
put the arrayData of me into tTreeData
put tTreeData & tHilitedElement
end hiliteChanged
I’ve tried various forms of brackets around the tHilitedElement variable
containing the nested key string with no success - what am I doing wrong?
TIA.
Best,
Keith
_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
--
Jacqueline Landman Gay |[email protected]
HyperActive Software |http://www.hyperactivesw.com
_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode