GM_TEXTEDITOR_AddChangeListener

Online Status

Someone posted a thread on EAB asking how to get GM_TEXTEDITOR_AddChangeListener working. They managed to do it and I asked how they did it and I got no reply so I'll ask here.

I tried to get this working for myself and I am unable. It just crashes when I try to add the change listener.

	printf("Char entered: %c\n", character);
}

struct ChangeListener *textInputChangeListener;
struct Object *textInputTextEditor;

void openGUI() {
	// Code that creates the gadgets and opens the window is above but omitted in this forum post

	textInputChangeListener = AllocVec(sizeof(struct ChangeListener), MEMF_CLEAR);
	textInputChangeListener->onCharEntered = something;
	DoGadgetMethod(textInputTextEditor, mainWindow, NULL, GM_TEXTEDITOR_AddChangeListener, textInputChangeListener, NULL);

	// The system has now crashed
}

Online Status

Hi

If you look at the GP_TEXTEDITOR_AddChangeListener you will see it is not a gadget method so it should be installed like this:

DoMethod(textInputTextEditor, GM_TEXTEDITOR_AddChangeListener, listener, NULL);

Additionally you should note that the "something" function likely takes the arguments in A0 and D0.

I say likely as it unfortunately is underspecified, so please experiment a bit with the arguments

Online Status

@nightfox - my code is all assembler and as such uses a bunch of my assembler "idioms" to get stuff done! Happy to provide code snippets if you really want to see how I did it. However, @boemann's advice above is spot on. You effectively need to pass the address of a function/routine that conforms to ChangeListener. In my case, it's just a pointer to some code that sets a flag and enables a save button.