Get a value BACK from subclass event

a) I have subclassed a Canvas call it MYCANVAS
b) this canvas has a custom event, call it MYEVENT with an argument of MYCOLOR
c) when a particular action happens within MYCANVAS, it raises MYEVENT

Now the user code external to MYCANVAS, can see this event…
What I would LIKE to happen is have the user be able to call their own code to manipulate MYCOLOR, and then have MYCANVAS respond based on what the user returned.

<do some stuff>
 mycolor=&cff0000
MYEVENT(myCOLOR)
// would like myColor to be what ever the user altered it to be with THEIR code.....
// OR return the passed color unchanged, if they did not implement the event response on their side

What I want is for the user to decide what (if any) color selector they want to implement…

kinda like a plugin… but not a plugin if that makes sense

When the canvas needs a color it raises the event, the users does whatever they want to provide a color selection and that can be returned to the canvas

Basically the canvas has

          event def GetColor() as Color

which the user implements and returns a color from

But you also want the user to have a “method” like way to set the color ?
You’ll have to have a different name - like SetColor that the using code can call when they want.

So I raise the event just like any other custom event…
and the user in their response code would call “setcolor” (or a name of my choice)
which would be a public method in my subclass canvas…
and if they Don’t want to do anything, they simply don’t do anything…

Ok… now… is there a WAY to know they didn’t implement a custom response, so I can implement a DEFAULT response?

Say I want a color, they don’t code the external event… I want to call the system color picker… So something happens when the event is raised even if the developer doesn’t implement a custom response

[quote=165236:@Dave S]So I raise the event just like any other custom event…
and the user in their response code would call “setcolor” (or a name of my choice)
which would be a public method in my subclass canvas…
and if they Don’t want to do anything, they simply don’t do anything…
[/quote]
Pretty much

no

Can’t you pass myCOLOR ByRef? And add a boolean return value to indicate that the user “handled” the event?

Actually I came up with a easy way to do it

EVENT GetColor(byref myColor) as boolean

in the subclass

If GetColor(old_color) then msgbox "I got a new color="+str(old_color)

The external response to the event must return TRUE

LOL… didn’t read your response until I submitted mine… but as you see, that is EXACTLY what I did

except that … if you raise the event
the person throws up a dialog & grabs a color & returns “FALSE” you really still dont know
there’s no definitive way

this is a “by convention” mechanism
its the same as forgetting to return true from mouse down key down etc when you HAVE handled it

Exactly

Hence why I said

[quote=165321:@Norman Palardy]
no[/quote]
At least “no definitive way”
What you’ve suggested is about as good as you’ll get

And since if follows the convention used by MouseDown, KeyDown etc… I’m perfectly fine with this implementation.

Thanks

NP
This design pattern where the EVENT acts like a “request” is really useful
It lets you design reusable controls / components that can use events to get information back about their working environment without having to know about it or reach around inside other controls / windows etc

Yup :slight_smile:
I don’t know if you saw/read the other topic about the “spreadsheet/listbox” control I am working on… but that is exactly where this is going to be used… By default the color cell type will use the “system” color picker, unless the user assigns another method, the same for the Date/Time cell types, they can supply a date picker, or it will default to “type it in”… This way they are not constrained by the type of color or date picker that I like.

hadn’t read that thread

well here :slight_smile: take a look

https://forum.xojo.com/19539-what-i-m-working-on-need-feedback