Function Request: ExposeEvents and Handles

That double work …
btnBewaren.Click should be enough.

I don’t like it at all.
This becomes a very ugly solution this way; not readable, not maintainable.
Looks like Aspects are not the right solution (maybe the easy one, but not the right one).

And it does not work.
It causes a perpetual loop, because the field and the property have the same name, causing the property to set itself.

That loop mgiht be a bug in the aspect code.

As for expressions: I’ll have to think how to best solve that, odds are it will involve expressions be compatible with Cirrus’ Value in aspect calls.

Do you have a current version of the aspect + usage code I can use ?

The loop is solved, but the generated code doesn’t work - it doesn’t see the methods of the owner of the field.
I am working on that now.

Edit: The problem is that the field is on another component.
And another problem is inherited fields.

@ck
It is a lot more complex than at first look.
The way you implemented it, only works for components directly on a form.

But:

  1. It doesn’t have to be a component; any type that defines events should work
  2. The declaration and event implementation can be static
  3. The ExposeEvents and Handles doesn’t have to be in the same module (or even project)
  4. If it is a component, it could be nested

Solution for 1: The ExposeEvents attribute (or modfier) should be valid on any type that has events - check using reflection?

solution for 2: Check needed: if the variable that exposes events is static, then all handlers must be static too, if it is not, the handles should also not be static

solution for 3 (this is only possible in a child class)
The properties should be overridable; if the handler is in another code unit than the ExposeEvent, the property should be overridden to add the extra handler.

solution for 4: The complete class should be searched, including partial classes

I’ll comment on the rest tomorrow when I’m back in the office, but for (4); the accessors in Cirrus expose the full classes, not just the partials.

Almost there - how do I call inherited with the statements?

https://docs.elementscompiler.com/API/Cirrus/Classes/ProcValue/

Use the overload with ainherited

I have it working :blush:
Class1.zip (2.0 KB)

All problems solved except for the typename in the Handles aspect.
If you can solve that one, I would be very happy.

problem 1: was non-existent
problem 2: solved
problem 3: solved
problem 4: was non-existent

2 Likes

One bugfix on the inherited level - the visibility is now copied from the original.
Edit: and an error is thrown when you use handles on a variable that does not ExposeEvents.
Class1.zip (2 KB)

For fridays’ build:

Usage:

    [ClassLibrary1.Handles(btn.Click)]
  HandlesAspect = public class(Attribute, IMethodInterfaceDecorator)
...
    constructor (aEvent: Value);
    begin 
      constructor(aEvent.ToString());
    end;

...
          //eventname: var.event or inherited.var.event or self.var.event
          var eventNameValue := Att.GetParameter(0);
          var EventName := if (eventNameValue is DataValue) then eventNameValue as String else eventNameValue.ToString();
          var firstpos := EventName.IndexOf(".");

works.

2 Likes

Carlo,

Another bugfix - checking he signature of the eventhandler:
Handles.zip (2.4 KB)
The HandlesAspect.HandleInterface(Services: IServices; &Method: IMethodDefinition) is changed completely. There is also a question for you in the code comment of this method.

You can’t update the source itself from Cirrus, but you could just change the signature like how you did with AddParameter & RemoveParameter.

//Carlo: Question; can the sourcecode be updated from here to correct the signature?

Clear, then I leave it with the error that points out the wrong signature.

Is this all good for you now?

What reference do I need; It does not recognize the attributes.

What I mean is, with fridays’ build is everything working for you with the aspect now? If so I can integrate the latest version in the compiler so you don’t need to explicitly reference it.

The last version I send you is working correctly (as far as I known now).