| View previous topic :: View next topic |
| Author |
Message |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3327
|
Posted: Mon Aug 26, 2024 4:16 am Post subject: Getting value of right-clicked Data Dissect Structure Entry |
|
|
Hi all,
here, I learned how to add a context menu.
I am having a hard time figuring out how to retrieve the value that was right-clicked.
How would I figure out which instance of the form was right-clicked?
How would I figure out which value was right-clicked? (there are multiple columns)
How would I find the Element associated with the value so I could check whether it's a hex or a decimal value?
Thank you! |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25807 Location: The netherlands
|
Posted: Mon Aug 26, 2024 5:53 am Post subject: |
|
|
the menuitem has an OnClick handler. When executed the first parameter is the sender, which the menuitem itself
Usually menuitems belong to the form, so sender.Owner will get you the to get the form (structure dissect) If for some reason it doesn't, get the parent until the base, then get the Menu from there (which is the popupmenu) and then find the parent on that one to the mainform. But try the owner first
(tip: When testing click handlers, assign the received parameters as global lua variables, so you can inspect them with lua engine later)
---
Then when you have the structform you can enum the Columns (0 to structform.ColumnCount-1)
Each column has a property named "Focused" which is the one currently active. Rightclicking the list makes a column focused
then to get the element you should have been able to use structform.getSelectedStructElement() but that seems to be broken for me atm (might be a 7.6 beta issue, or always broken. I got to check it out)
So since that's not an option you'll have to use structform.tvStructureView.Selected.Index to get the current index and cross reference that index with the structform.MainStruct . Note that you should check the .Level property of the selected entry, as the index is relative to the parent node and follow pointers(nodes with children) accordingly _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3327
|
Posted: Mon Aug 26, 2024 10:49 am Post subject: |
|
|
Thank you Dark Byte!
Below is the code so far. Output:
| Code: |
Registered popupLookupNameIDClick.
owningForm.ClassName: TPopupMenu
Error:[string "local syntaxcheck,memrec=...
..."]:21: attempt to perform arithmetic on a nil value (field 'ColumnCount') |
I got as far as for i=0,owningForm.ColumnCount-1 do
That is the only place where ColumnCount is used.
| Code: | function popupLookupNameIDClick(sender)
if sender==nil then showMessage('No sender?') return end
local owningForm=sender.Owner
if owningForm==nil or owningForm.ClassName~='TPopupMenu' then
showMessage('Owner missing? owningForm.ClassName: '..owningForm.ClassName)
return
end
print(string.format('owningForm.ClassName: %s', owningForm.ClassName))
local i
local columnCurrent
local columnFound=nil
for i=0,owningForm.ColumnCount-1 do
columnCurrent=owningForm.Column[i]
print(string.format('columnCurrent.ClassName: %s', columnCurrent.ClassName))
if columnCurrent.Focused == true then columnFound=columnCurrent end
end
if columnFound==nil then showMessage('Active column was not found.') return end
i=columnFound.Address
if not i or i<=0 then showMessage('Active column has no valid value.') return end
print(string.format('columnFound.Address: 0x%X', i))
i=owningForm.tvStructureView.Selected.Index
if not i or i<=0 then showMessage('Selected Index was not found.') return end
print(string.format('owningForm.tvStructureView.Selected.Index: 0x%X', i))
end
|
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25807 Location: The netherlands
|
Posted: Mon Aug 26, 2024 11:08 am Post subject: |
|
|
i think when you create the menuitem you use the menu as owner instead of mainform so try sender.owner.owner _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3327
|
Posted: Mon Aug 26, 2024 1:46 pm Post subject: |
|
|
That did the trick!
| Code: | Registered popupLookupNameIDClick.
owningForm.ClassName: TfrmStructures2
columnCurrent.ClassName: TStructColumn
columnFound.Address: 0x7FF7738A7000
owningForm.tvStructureView.Selected.Index: 0x15
|
How can I use that index to fetch the data from columnFound?
I am not seeing any members/methods exposed in celua.txt.
I.e. columnFound[owningForm.tvStructureView.Selected.Index] |
|
| Back to top |
|
 |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3327
|
Posted: Wed Sep 18, 2024 9:00 am Post subject: |
|
|
I have a new problem.
The code works when I right-click a top level element.
However, I seem to get back something completely wrong when I right-click on an element that belongs to a child structure.
Probably this is the reason why:
| Code: | local e=mainStruct.getElement(owningForm.tvStructureView.Selected.Index)
|
This always takes the element from the main struct - not from the node open.
The open node does not have a getElement() member, does it?
Any tips?
Any chance to fix this in the next release?
| Dark Byte wrote: | you should have been able to use structform.getSelectedStructElement() but that seems to be broken for me atm (might be a 7.6 beta issue, or always broken. I got to check it out)
|
Thank you! |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25807 Location: The netherlands
|
Posted: Wed Sep 18, 2024 2:50 pm Post subject: |
|
|
You'd have to go up to the node parent and check it's .data property, convert it to a class (which will be a structure itself) and then use the relative index of the selected node to get the structure element index
it is fixed in the next version and supports multiselect _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Csimbi I post too much
Reputation: 97
Joined: 14 Jul 2007 Posts: 3327
|
Posted: Wed Sep 18, 2024 3:31 pm Post subject: |
|
|
Ok, thanks!
I will wait for the next release; it will be far better than what I could cook up
Much appreciated! |
|
| Back to top |
|
 |
|