Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Extending EditString to filter keys
Re: Extending EditString to filter keys [message #31170 is a reply to message #31168] |
Fri, 11 February 2011 14:08   |
|
Hi Jeremi,
There is a litle bit simpler way. All the U++ edit fields based on EditField have a method SetConvert(const Convert&), which allows to handle how seting and retrieving values work and, most importantly for you, it allows to filter which characters are alowed.
All you need to do is to create a class inherited from Convert and override its Filter method. The code could be something simple such as:class MyConvert:public Convert{
public:
virtual int Filter(int chr){
return IsAlpha(chr)?chr:0; //return 0 if we want to discard the character
}
};
Then you can use it as myeditstring.SetConvert(MyConvert()) and it will filter out all characters except letters. For full description of Convert have a look in manual. Nice examples can be found Core/Convert.{h,cpp}.
Best regards,
Honza
PS: I wrote it from top of my head, hopefully there are no big mistakes...
|
|
|
Goto Forum:
Current Time: Sun Apr 27 00:32:15 CEST 2025
Total time taken to generate the page: 0.00796 seconds
|