I have created a class called TF_CleanText which is a subclass of TextField. This contains code in the KeyDown event handler to make sure that only valid characters are entered. I’d like the same class to be used for a TextArea. Is there anyway to do this?
I seem to remember discussion on the NUG about being able to do this with a TextEdit when they were first introduced, but can’t see how.
Thanks in advance,
Mark
First, I would use the TextChange event rather than KeyDown unless you don’t mind if pastes and drags contain invalid characters.
To answer your question as asked, no, you would have to subclass each, but you can call the same method(s) from both. Or you can just use the TextArea which can be made to act like a TextField (mostly).
TextArea and textField are both TextEdit children
If you want to share the same code, you could write an extension in a module:
function myKeyDown(extends te as textEdit, key as string) as boolean
… my stuff
end function
and in the textArea/textField keyDown event:
return me.myKeyDown(key)
(the same for all the textEdit events / properties)
my application use textarea everywhere except the login and the user setup screen where i need the password feature with the ***
[quote=205654:@Antonio Rinaldi]TextArea and textField are both TextEdit children
If you want to share the same code, you could write an extension in a module:
function myKeyDown(extends te as textEdit, key as string) as boolean
… my stuff
end function
and in the textArea/textField keyDown event:
return me.myKeyDown(key)
(the same for all the textEdit events / properties)[/quote]
Could use AddHandler and tie the two events together… dozens of ways to do the same thing
You could also apply a mask and use RegEX to ensure correct values are entered
http://documentation.xojo.com/index.php/TextEdit.Mask