Function Request: ExposeEvents and Handles


(Carlo Kok) #53

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.


(Theo) #54

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.


(Carlo Kok) #55

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?


(Theo) #56

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


(Carlo Kok) #57

Is this all good for you now?


(Theo) #58

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


(Carlo Kok) #59

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.


(Theo) #60

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


(Theo) #61

Did you add this to the code in Cirrus? - Because I do not think it was in my last code.


(Carlo Kok) #62

I think the code you posted last was more incomplete than that. Can you send the full thing?


(Theo) #63

It was complete, except for the value constructor.
Handles.zip (2.4 KB)


(Carlo Kok) #64

that one doesn’t have the constructor either. Nor does it do tostring if it’s a value (as string will fail)


(Theo) #65

oops wrong version.
Handles(1).zip (2.4 KB)


(Carlo Kok) #66

Should be fixed.


(Theo) #67

Carlo,

I found several bugs in the code, by Example, the Handles could be processed before the ExposeEvents.
As far as I can see, I fixed them all, except for one.

The call:
Meth := Typ.GetMethods(“set_” + VarName).FirstOrDefault

Does not return anything when the class is a static class or when the ExposeEvents variable is a static variable (making the generated property a static property).

Looks like a bug in IType.GetMethods. Same for IType.GetFields.


(Carlo Kok) #68

Isn’t there a getstaticmethods API? And same for field.


(Theo) #69

Yes there are :smile:
Didn’t see them before.

It works now in all cases I can (now) think of.
New code:
Handles (2).zip (2.5 KB)


(Carlo Kok) #70

Thanks. In.


(Theo) #71

Works :smile:
One point: I have to use [ExposeEvents.ExposeEvents] and [ExposeEvents.Handles(…)] instead of [ExposeEvents] and [Handles(…)]
Can you fix that?


(RemObjects) #72

Thanks, logged as bugs://80796