How to create a new event definition

I want to create for a textarea an event definition/handler that fires when the method paste fires.

There is a post sort of around this. Sort of because I don’t think it helps.
making a custom event handler

They also mention a chapter that I can’t find.

I know there were articles in XDEV, but I can’t find them.

Suggestions?

Look here:

http://developer.xojo.com/userguide/properties-methods-and-events

[quote=364111:@Arthur Gabhart]I want to create for a textarea an event definition/handler that fires when the method paste fires.

There is a post sort of around this. Sort of because I don’t think it helps.
making a custom event handler[/quote]

On the contrary, that thread explains very well how to create and use an event definition.

If you think otherwise then your preconception might hinder you (happened to me often enough). Forget how you THINK it should work and read that thread again. It is full of good advice!

Thsanks to both. Sorry if I am too short. On a mobile phone.
There are 2 things I am confused about.

  1. I already have classes as the textarea. Do I have reclass them?
  2. How do I handle a predefined method like “paste”. You usually do not handle with words. It happens. Like control-V

[quote=364117:@Markus Winter]On the contrary, that thread explains very well how to create and use an event definition.

If you think otherwise then your preconception might hinder you (happened to me often enough). Forget how you THINK it should work and read that thread again. It is full of good advice![/quote]

Trust me, that thread only makes sense after you know how to add event definitions. It is not concise or straightforward at all. You really have to catch Simon and Tim’s comments.

Nope, not trusting you :wink:

Sometimes I had to read things 20 times (I’m not exaggerating) before I understood them.

Is the thread concise? Actually not too bad. Just 19 posts, and most of the postings are fluff (like “Covered in book 1” or “I’m re-reading again” or “Thank you”) that can easily be ignored. There are only three short postings with explanations that need to be read and digested.

Is it straightforward? Those three postings are pretty good, explaining not just how to create an event definition, but also how to use it.

Most importantly all the required information is in there. It might require reading a few times but you can get it.

That Arthur thinks it isn’t really helpful to answer his question shows that the problem is likely not in the way the information is given or the information itself, but more likely in the way he thinks about event definitions. My suspicion is that he wants to add an event definition to the actual build-in TextArea base class, and hasn’t realized that you can’t modify the base class itself, but only your own subclass of a base class.

I often had to teach students, and the most difficult thing has always been to overcome wrong ideas that they developed from the information they had acquired or been taught.

A related experience: I myself come from a procedural programming background, and it took me quite a long time to get into object-oriented programming. It still doesn’t come naturally, and I’m more familiar with flow diagrams and mapping all the steps in a procedural manner.

Yes that is one question, and you just confirmed I do have to sub-class it. So I have to even though I can add my event-definition to my class?
The other question is detecting the firing of a pre-defined method - paste
This has a method callout in the LR, but there is no coincidental event. There are things like drop and copy, but not for paste

The article I thought might answer will not from its title.

Its from Real Basic Developer 2.1

No, you can’t.

EVENT HANDLERS handle events that you defined in EVENT DEFINITIONS.

If (in 2017R2.1) you select a TextArea and press “+” and click on Event Definition, then you do NOT add the event definition to the TextArea but to the Window (I consider this a bug as you should not be able to do this either).

You can add EVENT HANDLERS to a base class like TextArea but NOT EVENT DEFINITIONS.

EVENT DEFINITIONS are for CLASSES (including Subclasses), which become EVENT HANDLERS in INSTANCES (and I hope you know the difference between a class and an instance of a class, otherwise this will make no sense to you).

You can make a new class MyTextArea (by selecting INSERT -> CLASS from the menu), set it’s super to TextArea, and this SUBCLASS MyTextArea inherits all the events, methods, and properties from the base class TextArea.

And now you can define new events by adding new EVENT DEFINITIONS to your SUBCLASS MyTextArea.

Where do you see those events that you just defined? When you drag the SUBCLASS MyTextArea onto the window and thereby create an instance of MyTextArea, then NOW you can add an EVENT HANDLER for your EVENT DEFINITION.

My advice: get one of the short tutorials on object-oriented programming (for example the one from Scott Steinman)

Thanks. I have never been sure since every single control is a class. What you wrote makes more sense.
Now if someone knows the answer to my other question…

On my way to bed, so google for “Xojo override Paste event”

Last entry on the first hit https://forum.xojo.com/8489-text-area-intercept-copy-paste-events/0

The key takeaway here is that Paste is a menu action, not an event. You need a menu handler, not an event definition.

Thank you. I guess I cannot do what I want.
Just to be clear, I’m not referring to the menuitem paste.

I am referring to the method called paste on the textarea control’s page TextArea .
It is after events and properties.

TextEdit.Paste
I can easily add to my menu item for paste the code I want.

TextEdit.Paste is a method, not an event or even handler.
It can be CALLED from an event handler , as most like is done by the ctrl-V and menu events

based on what you say you want to do… can’t be done… at least not that way

An Event is something that occurs due to some stimulus (ie. and EVENT :slight_smile: )… such as pressing a key, moving a mouse, a timer going off etc…

So when you press CTRL-V, there is an EVENT handler that responds to the EVENT of pressing the key… That handler calls TextEdit.Paste (or an equivalent method)… but it is not the CAUSE but rather the EFFECT

Basically you are wanting an EVENT that is generated by a predefined EFFECT, but EFFECTS are the end of the line in this case

Now you can respond to the TEXTCHANGE event, which occurs when the content of the TextArea changes, however the CAUSE for this EFFECT could be keypress, delete, or PASTE… but it doesn’t indicate how it was invoked.

Btw Scott Steinmsan’s introduction to OOP “Beginning Object-Oriented Programming with REALbasic” is available at http://www.rblibrary.com

Sure can. Made a little project for Arthur (hope the Dropbox link works): https://www.dropbox.com/s/etlx8o2aj5neopr/CustomMadeForArthur.zip?dl=0

To make it easier to follow I prefix the name of a class with class, and that of the instance with instance.

Add a normal text area to the window for comparison

make a custom class classMyTextArea and set it’s super to TextArea. Now you have your own TextArea-type class to modify as you wish:

  • add an event definition MyEventDefinition
  • add a menu handler to custom class classMyTextArea, set it to EditPaste from the dropdown menu
  • in the menu handler now simply call your event MyEventDefinition. If you return TRUE then that means “I handled the paste, the system does not need to do anything”. If you return FALSE then you do not do it all but pass the event on to the system for further processing (just try it out)

drag an instance of your custom class classMyTextArea to the window

  • add your event handler for MyEventDefinition to the instance
  • write some code into the event handler (e.g. MsgBox “works”)

The end result is that you have a custom TextArea class that reacts to the paste event by calling your custom event.

Thanks, Dave, for confirmation.
I was really trying to avoid writing some lines of code.
I guess in my original have included this reference to AcceptTextDrop .
If that can be a standard event then maybe, but no luck.

Here’s the code I wrote. CtrlFocus is the equivalent of an event definition’s index.

If CtrlFocus > -1 Then CREdit(CtrlFocus).Paste CREdit(CtrlFocus).Text = ReplaceAll(CREdit(CtrlFocus).Text, EOL, L2Fd) CREdit(CtrlFocus).Text = App.CleanChars(CREdit(CtrlFocus).Text, True) //SetFontSize(tCont As TextArea, onePrt As Boolean, shwNoDggrs As Boolean, strFDisplay As String) If CtrlFocus <> 2 Then App.SetFontSize(CREdit(CtrlFocus), True, False, CREdit(CtrlFocus).Text) Else App.SetFontSize(CREdit(CtrlFocus), False, False, CREdit(CtrlFocus).Text) End If End If Return True

What Dave says is right but not correct. Because you CAN intercept calling the paste method and thereby modify what it does, so for example call your custom event. Which is what my example does.

Why do I bother …

Thank you for bothering to write the code. I had not read deep enough. I see the custom menuhandler now. It makes more sense.
When I get the relevant stuff done, I’ll post. It won’t be a working class but…

I’ll also take a look again at the book. I had looked at it but associating terminology like “OverRide” with this problem is something I don’t get until it is applied.
My personal evaluation of something like this book that is looking for a definition in this case of something like encapsulation and Private, and the book didn’t add any clarity to it.