hi
sorry for my stupid question
what are the right way to create multiple control object from a list of array of label of object ...?
thank
The function wxCreateDynamicObject can be used to construct a new object of a given type, by supplying a string name. If you have a pointer to the wxClassInfo object instead, then you can simply call wxClassInfo::CreateObject.
You must include the IMPLEMENT_DYNAMIC_CLASS macro in every class you want to be able to dynamically create objects. IMPLEMENT_DYNAMIC_CLASS is a macro that not only initialises the static wxClassInfo member, but defines a global function capable of creating a dynamic object of the class in question.
Example
In a header file:
class wxFrame : public wxWindow
{
DECLARE_DYNAMIC_CLASS(wxFrame)
private:
wxString m_title;
public:
...
};
In a C++ file:
IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
wxFrame::wxFrame()
{
...
}
Related
I'm creating an Array of a Class Type (Button), and I want to have a subclass of it called ButtonMb inside the array Button
Is that possible?
I tried to have two different constructors and use only one Class, but since number of parameters are the same, I couln't reach anywhere.
Here is my code:
for simplicity I only included header code for class declaration
typedef void (*Callback)(void);
typedef int (*CallbackInt)(void);
class Button {
public:
OneButton _pin;
Button(uint8_t pin, Callback click=NULL, Callback longCl=NULL, Callback dblCl=NULL);
void loop();
};
class ButtonMb : public Button {
public:
CallbackInt _pinState;
ButtonMb(CallbackInt pinState, Callback click=NULL, Callback longCl=NULL, Callback dblCl=NULL);
void loop();
};
Button buttons[2] = {
Button(14),
ButtonMb([](){return slaves[0].getState("A15");)
};
Any help?
NOTE: I'm using Arduino, so code can be limited.
Instead of using array of objects, you can create array of pointers. Pointers of base class can point to derived classes, so you can have pointers to objects of different types in one array.
As title, is there any way to iterate or display Apache velocity template attributes?
for example, I have following code :
<code>
${ctx.messages.headerMessage}
</code>
And I want to know how many other attributes the variable ${ctx} has
It's only possible to discover and to loop on an object properties (that is, the ones with getters and/or setters) if you can add a new tool to your Velocity context. If you can't, you're rather stuck.
There are several ways to do this, I illustrate below how to do this with commons-beanutils.
First, add Apache commons-beanutils in your class path, and add it to your Velocity context from Java:
import org.apache.commons.beanutils.PropertyUtils;
...
context.put("beans", new PropertyUtils());
...
One remark: if you do not have access to the Java part, but if by chance commons-beanutils is already in the classpath, there is one hakish way of having access to it: #set($beans = $foo.class.forName('org.apache.commons.beanutils.PropertyUtils').newInstance()).
Then, let's say that I have the following object:
class Foo
{
public boolean isSomething() { return true; }
public String getName() { return "Nestor"; }
}
which is present in my context under $foo. Using your newly $beans properties introspector, you can do:
#set ($properties = $beans.getPropertyDescriptors($foo.class))
#foreach ($property in $properties)
$property.name ($property.propertyType) = $property.readMethod.invoke($foo)
#end
This will produce:
bar (boolean) = true
class (class java.lang.Class) = class Foo
name (class java.lang.String) = Robert
(you'll need to filter out the class property, of course)
One last remark, though. Templates are for coding the View layer of an MVC application, and doing such a generic introspection of objects in them is rather inadequate in the view layer. You're far better of moving all this introspection code on the Java side.
How do I get the object type that a PsiMethodCallExpression refers to?
eg
Object x = new Object;
x.hashCode();
I can use the visitor and get the PsiMethodCallExpression, and I can get "hashCode", but how do I get "Object"?
As you can learn from the javadocs to the APIs in question, you can obtain the method being called by calling PsiMethodCallExpression.resolveMethod(), and after that you can obtain the class where the method is declared by calling PsiMethod.getContainingClass().
Edit - just added some code to make it obvious for all and sundry, use the "accept" method with the following:
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
super.visitCallExpression(expression);
PsiUtil.getMemberQualifiedName(expression.resolveMethod());
expression.resolveMethod().getContainingClass().getName();
expression.resolveMethod().getContainingClass().getQualifiedName();
}
When you're instantiating an object of a class that inherits from a parent class the constructor calls the superclasses constructor in most langiages I know and my question is: when the superclasse's constructor is called there will effectively be an object of that type in memory, but we're creating an object of the subclass with(in this example) additional values to add to the object so how is that accomplished in memory? Is it added to the original object? Are the contents of the original object copied into a new object with space for all the variables? Or is it something completely different?
A different question that just occured to me, are class variables, like in java, kept in the data segment of the program in memory? How are classes, not the objects, stored in memory for that matter?
Thanks.
I don't really know how engine works, but I know how to test memory usage in PHP. Both scripts
class base {
public function __construct() {
}
}
$start_memory = memory_get_usage();
$object = new base;
echo memory_get_usage() - $start_memory;
and
class base {
public function __construct() {
}
}
class derived extends base {
public function __construct() {
}
}
$start_memory = memory_get_usage();
$object = new derived;
echo memory_get_usage() - $start_memory;
return the same value. It means there'is only one instance in memory, not parent + it's child, when class is extended
phpfiddles: 1st script, 2nd script
Classed are code that define its object, so they are in Code Segment of program. And all class variables are in data segment.
And when we create an object of subclass, first its parents' object are created and it is extended for subclass members. That's why subclass object has all members of its parent class.
I want to create a variable(possible global variable) in one action script file and want to use the same variable across all other action script files in the project. How to create such a variable and how to use the same variable across all .as files??
One simple way is to define a static variable in a Class (either create a new Class or use one of your existing classes):
// in MyConfig.as
class MyConfig {
static var myVariable:String = "Hi";
}
// You can access / set the value from any class using MyConfig.myVariable
trace(MyConfig.myVariable); // prints Hi
MyConfig.myVariable = "Hello";
trace(MyConfig.myVariable); // prints Hello
Create one public class (lets assume GlobalVariables.as)
No need to add its instance.
Now declare all the variables that you want to use across multiple classes as STATIC.
(you can also declare and create instances of classes in that class to avoid multiple instances of classes)
Also you can add common methods to this class
So whenever you want to access that variable declared in GlobalVariables class
you need to access using reference e.g GlobalVariables.variableName
sample code:
package classes{
public class GlobalVariables{
public static var strURL:String;
public static function setExternalLinks(){
strURL = "http://demourl.asmx/";
}
}
}