How to programatically determine the name of the active control in livecode - livecode

I have a code script in a stack that runs on KeyboardActivated. The codes needs the name of the active control. I can get that by adding on openfield code for each control that generate a KeyboardActivated. But is would be much easier of there was a way for the stack to know which control is active. Is that possible?

You could use a front script. To designate a script a front script, use this syntax
insert the script of control x into front
You can use an openField handler:
global gLastOpenedField
on openField
put the long id of the target into gLastOpenedField
pass openField
end openField
The front script will catch all openField handlers and store the long id of the target into a global variable. Don't forget to pass the openField message on to the next level!

That is what Mark meant. If you trap the "openField" message in a frontScript, and do not pass it, it will be processed, but then discarded. The "pass" command does just that, sends it along the hierarchy.
You can think about this the other way around. If there were no "openField" handler in "front" at all, the message would pass normally through that hierarchy level without being trapped, (this is the normal way) and would then be available to be caught by that field you mentioned.
All handlers work this way. When a message is trapped, it is processed and discarded, unless explicitly passed. The only other way around this trashing is to use the "send" or "dispatch" commands, which can "pass" the message to any object, regardless of its place in the hierarchy.

Did you try using "the target"? I never use front/back scripts and always get things sorted that way. ie:
on KeyboardActivated
put [short] name of the target into MyVar
-- do your stuff

Related

A code to destroy the value of a variable in livecode

I have a question , I noticed that when I use a variable to count the score of clicks of different objects . The value of the score that uses variable whether it was a global or a local variable maintain its value of the score that has reached and continues to count from that point even when I close and re-open the app and I reset the variable value to 0 with code (put 0 into _gScorePlayer ) for example when a user reaches score 15 and closes the app , next time the score continues from 15 and so on
I am a beginner in livecode
Thanks fro your continues help and support guys :)
you can use the put command to clear the variable and the delete command to remove it from memory.
check the LiveCode dictionary
delete variable
Example
delete local tVar [1]
By default, declaring variables is optional in LiveCode.* Persistence of variable values is determined by whether the variable is declared outside of a handler or not. When a variable is only declared or used inside a handler, the variable is always temporary and its value is only valid while the handler is running.
The value of variables declared as local or global outside of a handler will persist between instances of the handler being run. However, the value of such variables will not persist between launches of LiveCode. That is if you quit LiveCode and launch it again, the values of the declared variables will be lost. However, if you only close the stack without quitting LiveCode, the stack remains in memory (by default) and the values of declared variables remain intact.
If you want to ensure that the variable is reset when the stack is reopened, do this for declared globals in the stack script:
global gScorePlayer
on openStack
put empty into gScorePlayer
# OR
put 0 into gScorePlayer
end open stack
To initialize local variables you do something similar in the script where the variable is used. For example, if you are using a local variable in a card script, you can do this in the card script:
local sMyLocalVar
on openCard
put empty into sMyLocalVar # or put 0 into sMyLocalVar
end openCard
*See the explicitVariables property in the Dictionary for more information about declaring variables.
The way I use to clean the content of a variable is:
delete variable VariableName

How can you hide passwords in command line arguments for a process in linux

There is quite a common issue in unix world, that is when you start a process with parameters, one of them being sensitive, other users can read it just by executing ps -ef. (For example mysql -u root -p secret_pw
Most frequent recommendation I found was simply not to do that, never run processes with sensitive parameters, instead pass these information other way.
However, I found that some processes have the ability to change the parameter line after they processed the parameters, looking for example like this in processes:
xfreerdp -decorations /w:1903 /h:1119 /kbd:0x00000409 /d:HCG /u:petr.bena /parent-window:54526138 /bpp:24 /audio-mode: /drive:media /media /network:lan /rfx /cert-ignore /clipboard /port:3389 /v:cz-bw47.hcg.homecredit.net /p:********
Note /p:*********** parameter where password was removed somehow.
How can I do that? Is it possible for a process in linux to alter the argument list they received? I assume that simply overwriting the char **args I get in main() function wouldn't do the trick. I suppose that maybe changing some files in /proc pseudofs might work?
"hiding" like this does not work. At the end of the day there is a time window where your password is perfectly visible so this is a total non-starter, even if it is not completely useless.
The way to go is to pass the password in an environment variable.

Equivalent of String.Format in a Chef/Bash Recipe

looking for something similar to .Net string format in a chef recipe ie.
string phone = String.format("phone: {0}",_phone);
I have a Chef recipe where I need to build up a command string with 30 of these params so hoping for a tidy way to build the string, in principle Im doing this
a=node['some_var'].to_s
ruby_block "run command" do
block do
cmd = shell_out!("node mycommand.js #{a}; exit 2;")
end
end
When I try this I get the error
Arguments to path.join must be strings any tips appreciated
Chef runs in two phases:
Compile and Execute (see https://www.chef.io/blog/2013/09/04/demystifying-common-idioms-in-chef-recipes/ for more details).
Your variable assignment to a happens at compile time, e.g. when chef loads all recipes. The ruby block will be execute in execution mode at converge time and cannot access the variable a.
So the easiest solution might be putting the attribute into the ruby block:
ruby_block "run command with argument #{node['some_var']}" do
block do
shell_out!("node mycommand.js #{node['some_var']}")
end
end
However:
If you don't need to execute Ruby code, consider using the execute or bash resource instead.
Keep in mind, that you must have a unique resource name, if you're building some kind of loop around it. An easy way is to put something unique into the name ruby_block "something unique per loop iteration" do ... end
What I really don't understand is your exit code 2. This is an error code. It will make chef throw an exception each time. (shell_out! throws an exception if exit code != 0, see https://github.com/chef/chef/blob/master/lib/chef/mixin/shell_out.rb#L24-L28)
The resource will be executed on each chef run. This is probably not in your interest. Consider adding a guard (test), to prevent unnecessary execution, see https://docs.chef.io/resource_common.html#guards

RPG get SFLSCROLL from mutiple format DSPF without responce wait

In RPGLE I'm try to get the SFLSCROLL from a DSPF with multiple formats displaying. I used a read of the SFLCTL to get the SFLSCROLL but the screen is waiting for a response.
How can get it to return to the program without the wait?
You can't.
From the manual: 'You use this field-level keyword in the subfile-control record format to return the relative record number of the subfile record that is at the top of the subfile when control is given back to your program.'
You could use WAITRCD() on CRTDSPF to cause a timeout, but you still need to wait for the timeout to expire.
Thank You I did see that solution but here it was a an order issue on the display.
There is a detail screen on the top of the screen then a subfile on the bottom.
(do not ask why the detail was not in the subfile control I think they had planned for multiple details in the header area)
They were doing a write of the sflctl then exfmt for the detail.
That was not giving me the SFLRRN to check new prompt in the subfile.
I changed it to do a write of the detail exfmt of the sflctl read of detail and that got all the data for me to process with them only hitting enter once after the display occurred so I could check the prompt in the subflctl:
C write dtl2
C exfmt sflctl1
C read dtl2

How to see output of TextOutW(...) after each call?

On writing to the display with:
::TextOutW( pDC->m_hDC, x, y, &Out, 1 );
It only shows on the screen after every 15 calls (15 characters).
For debugging purposes only, I would like to see the new character on the display after each call. I have tried ::flushall() and a few other things but no change.
TIA
GDI function calls are accumulated and called in batches for performance reasons.
You can call GdiFlush after the TextOut call to perform the drawing immediately. Alternatively, call GdiSetBatchLimit(1) before outputting the text to disable batching completely.
::flushall() is for iostreams, so it won't affect Windows screen output at all. I've never tried it, but based on the docs, I believe GDIFlush() might be what you want. You should also be able to use GDISetBatchLimit(1); to force each call to run immediately upon being called.

Resources