How to correctly use Context::Scope ? Do i allocate it while within a method/function scope while actually executing something or can i have a global copy of it next to the Context object ? The documentation isn't very clear on that.
I want to make a global Application class and keep all the persistent stuff there not sure if i can put context scope there.
Context::Scope has to be allocated on the call stack outside of your call chain. What you want to do is use a Persistent<Context> to store your Context object globally, and then create a Context::Scope when you enter a JavaScript call stack. This is the case for all of V8's scope objects (HandleScope, Isolate::Scope, etc.).
Related
I need to set properties on an object referenced by a Persistent handler. However, it seems like Persistent class doesn't have a Set method (unlike the Local class).
Does it mean that Persistent handlers are read only? What is the best way to set a property on a Persistent handler then?
Create a v8::Local from the v8::Persistent, then use that to call operations on the object (Set and/or others). Note that you need an active HandleScope for this.
v8::Persistent<v8::Object> my_persistent = ...;
v8::HandleScope scope(isolate);
v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate, my_persistent);
obj->Set(...);
(To be nitpicky: Local doesn't have a Set method either; what it does have is an operator-> overload that lets you call methods (including Set) on the thing that the Local refers to. If that thing isn't a v8::Object but e.g. a v8::Number, then it won't have a Set method.)
One of the features of the method based on the definition of Beckoff site is that:
All data of a method are temporary and are only valid while the method
is executed (stack variables). This means that TwinCAT re-initializes
all variables and function blocks, which you have declared in a
method, with each call of the method.
Is there any way to use a method in the plc loop as warm start!
it means that we use the method without re_initializing and method declare variations run just once at the first time we call it and the rest of the time that is called the variables retain their own values?
Yes, this is possible through VAR_INST or VAR_STAT.
Just declare your variables as VAR_INST/VAR_STAT instead, then they will retain their values between the calls.
VAR_INST means it will be unique for every instantiation of the function block of where the method resides, while VAR_STAT will act as a static/global (all instances will point to the same memory location).
https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2528798091.html&id=
https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2528787339.html&id=
What does the free method do in TProcess. It's used in several examples I found on the net but there's nothing in the reference about it? So far I used it and everything works fine. Can I continue to use it or should I use a different method?
It is the Free method defined in TObject, at the very root of the class hierarchy. This method does the same thing in every single class, there is nothing special with TProcess in this regard.
It is documented:
Free will check the Self pointer and calls Destroy if it is different from Nil. This is a safer method than calling Destroy directly.
I have a start screen with a log in button and a register button. Both lead to the same view controller, but its interface is based on a variable.
How can I make my startviewcontroller change this var, that can currently only be accessed from the mainviewcontroller?
I'm temped to say "just like you get access to any other classes properties. However, given you haven't shared any code it's may not be as simple. But in general you will need to have a pointer to an instance or shared instance (singleton) of your mainViewController. And of course those variables need to be public.
You would have to declare that variable global outside any class just below the import statements. You will be able to use the variable anywhere in your code.
import UIKit
var myGlobalVariable: Int
I am using an extension where I need to pass the variable is moving from block class back to model, I have used session it works sometime but not uniformly,
Is there any other way to pass it,
Thanks in advance,
try using Magento’s Registry Pattern
The three registry methods are
Mage::register
Mage::unregister
Mage::registry
The register method is how you set a global-like variable.
Mage::register('some_name', $var);
Then, later in the request execution, (from any method), you can fetch your variable back out
$my_var = Mage::registry('some_name');
Finally, if you want to make you variable unavailable, you can use the unregister method to remove it from the registry.
Mage::unregister('some_name');
Source
If you can use the Model as a singleton, you can try this:
Mage::getSingleton('yourmodule/yourmodel')->setStuff('xxxx');
and later
Mage::getSingleton('yourmodule/yourmodel')->getStuff();
if you don't know what singletons are you should maybe try the registry approach from epynic to prevent problems.