of course you can
in your constructors call just call raiseEvent
of course you can
but don’t you have to be careful … if the event references the object being constructed as it might not be fully (welll uh) contstructed.
Wouldn’t OPEN be safer?
Xojo constructors are more like java’s where the object IS fully constructed and they are just a spot to do initialization
Its why you can even call them JUST like normal methods if you want to re-initialize the object
Unlike the INIT routine in Swift then… the object isn’t “SELF” until the super.init is complete
Yeah constructors in C++ are similar
Since they are called as part of actually allocating the memory etc
In Xojo & Java the “constructor” is an “initializer” and all memory is already set aside AND everything is already set to default values
I assume internally they use a call to calloc which sets all memory to 0
I am getting confused now Norman - @npalardy - I work with evens all the time, but events raised within a Constructor method never arrive. Greg o’Lone seems to agree with me.
Here’s an example with raise event IN The app constructor
IF you use that exact same design, a subclassed control, and put a raiseevent in ITS constructor it WONT be raised
So the answer isnt consistent and depends on what it is you’re trying to do this with
Hi Norman, the links isn’t working.
in fact i create an object sometime after launching the app, another proces triggers it. And within the constructor of this class/object I want to raise events in order to have a sort of a working-trail. The project is in fact a Windows service, no controls.
sorry my bad
Whats going to listen to those events being raised ?
You cant hook up listeners using addhandler before the class exists like
AddHandler myInstance.EventDuringConstruction, AddressOf EventDuringConstructor myInstance = New Class
You get a nil object exception
Hi Norman, you gave a good example of having the supper of the app = class1. Understood. But as I am building some business objects (classes) for having in my library, I want them to be created and be used when needed by the (web/desktop) app, for example when the user wants to create a new project within the app, I setup a new datafile by using the businessobject to do so. It’s also possible that the user has multiple objects running. And since a lot can go wrong, I need to be able to receive events during (in fact after) the construction of the object. So, what I intend to do now is to create a one-shot timer object within the class and let this timer raise all collected events 1 ms after finalizing the construction.
Yeah thats about as close as you’ll get with certain patterns