import "ecere" class MyClass : Window { // These are called 'class member default values'. Note that they require a semicolon at the end text = "I am a Window"; hasClose = true; size = { 320, 200 }; } // When you have a class data type ('MyClass' here) + an identifier ('myClassGlobalHandleOnly' here), // but without the curly brackets '{' and '}', it is NOT an instantiation, but merely a handle which // you can assign to an existing MyClass instance. Only global and member instances (instances inside // other classes, which in turn get initialized) are reliably initialized to a 'null' (0) value. // These are akin to a C/C++ pointer, but in eC we just think of it as a 'handle'. MyClass myClassGlobalHandleOnly; // This one here gets instantiated! MyClass myInstantiatedObject { text = "Window 1", position = { 200, 200 } }; class MyApp : GuiApplication { // The class derriving from the Application or GuiApplication class is the program entry point and the application class. // If none is defined and "ecere" is imported, the GuiApplication will be the default application class. // Therefore defining one is not required, defining Window instances (e.g. the default New Project/Create Form's 'Form1 form1 { };' instance) // is enough to get a GuiApplication going. // Here for the sake of explaining how to use instances within a function/method, we'll create some instances // in our Application class constructor. Note that because we do it here, before the GUI system is initialized, // the windows will all be auto-created. If we were to dynamically create window instances later on after the // parent window (the desktop) has already been created, we would need to additionally call Create() on each of // those new Window objects for them to appear on the screen. MyApp() { // Note that 'local' variables (variables inside compound blocks within functions) do NOT // get initialized to 0, and contain whatever was on the stack, just like any other C/eC variable. MyClass myClassHandleOnly; // C++ counterpart: MyClass * myClassHandleOnly; // Here we assign a new instance to our handle. You could also write it: myClassHandleOnly = { }; myClassHandleOnly = MyClass { }; // C++ counterpart: myClassHandleOnly = new MyClass(); // You can do this here. I would need to see your full source code to see what error you were getting. // Note that in eC you very rarely require the '->' operator, because class members can be accessed // from handles using the '.' operator. The use of '->' is limited to interfacing with C code, // or very specific cases involving struct data types. myClassHandleOnly.text = "Window 2"; // You could have done both assignment and setting the property at once with: // myClassHandleOnly = { text = "Window 2" }; // Or do it all one one declaration line with a local instantiation: // MyClass myLocalClassInstance { text = "Window 2" }; // Note that a named instantiation (e.g. myLocalClassInstance), a handle declaration (e.g. myClassHandleOnly), and a regular // C variable declaration (e.g. int a;) are all 'declarations' // Anonymous instantiations (e.g. MyClass { text = "Window 2" };) and assignments (e.g. myClassHandleOnly = MyClass { }; ) are all 'statements' // eC enforces (currently as an error, to be changed to a warning) all declarations to be at the top of a compound block ( Within curly brackets: { ... } ) // This means that any declaration following a statement will cause a syntax error ( or a bunch of them! ), so beware! // A note about struct vs class: In eC there is a fundamental difference between struct and class. // Although eC was designed independently and without prior exposure from C#, the difference // between struct and class in both languages is very similar. // - struct instances are always allocated 'in place' (i.e. global storage, on the stack or in the containing object) // - class instances are always allocated on the heap } }