| View previous topic :: View next topic |
| Author |
Message |
Matrix Guest
|
Posted: Tue Jul 20, 2004 12:08 pm Post subject: Deriving TEdit (TEditNumber) |
|
|
Hi, I'm writing a new component descendind from TEdit which accepts only numbers.
This component has a new property MaxValue (int type). I'd like to check after every keystroke, that the edit's content never overcomes this value.
I tried to wrap the DoKeyDown, DoKeyPress, DoKeyUp functions but the edit's content still hasn't been updated yet, so when I check the content it still has the previous value.
Have yuo got any advice to check the edit's content using the keyboard????
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Jul 20, 2004 6:45 pm Post subject: Re: Deriving TEdit (TEditNumber) |
|
|
"Matrix" <f_l_a_v_i_o.ba.ri.so.ne (AT) el_s_a_g (DOT) it> wrote
| Quote: | This component has a new property MaxValue (int type).
|
Why not just use TCSpinEdit? It already does all of that.
| Quote: | I tried to wrap the DoKeyDown, DoKeyPress, DoKeyUp
functions but the edit's content still hasn't been updated yet,
so when I check the content it still has the previous value.
|
That is fine. Simply retreive the current value into a separate AnsiString,
then append the new key to it, then test the new value.
Gambit
|
|
| Back to top |
|
 |
Matrix Guest
|
Posted: Wed Jul 21, 2004 7:00 am Post subject: Re: Deriving TEdit (TEditNumber) |
|
|
| Quote: | I tried to wrap the DoKeyDown, DoKeyPress, DoKeyUp
functions but the edit's content still hasn't been updated yet,
so when I check the content it still has the previous value.
That is fine. Simply retreive the current value into a separate AnsiString,
then append the new key to it, then test the new value.
|
The problem is that you can insert a new number in any place inside the Edit's content not only at the end. I mean: if the Edit's content is 1023 and the caret position (for any reason) is between 0 and 2, and you press "5", the whole number to check (to know if it's over the Max) is 10523 and not 10235. Have you got any idea to solve this problem without writing hundred of lines of code????
TIA.
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Jul 21, 2004 7:17 am Post subject: Re: Deriving TEdit (TEditNumber) |
|
|
"Matrix" <f_l_a_v_i_o.ba.ri.so.ne (AT) el_s_a_g (DOT) it> wrote
| Quote: | The problem is that you can insert a new number in
any place inside the Edit's content not only at the end.
|
Retreive the current caret position and then insert the keystroke into that
position of the AnsiString.
Gambit
|
|
| Back to top |
|
 |
Matrix Guest
|
Posted: Wed Jul 21, 2004 9:03 am Post subject: Re: Deriving TEdit (TEditNumber) |
|
|
"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote:
| Quote: |
"Matrix" <f_l_a_v_i_o.ba.ri.so.ne (AT) el_s_a_g (DOT) it> wrote in message
news:40fe1483$1 (AT) newsgroups (DOT) borland.com...
The problem is that you can insert a new number in
any place inside the Edit's content not only at the end.
Retreive the current caret position and then insert the keystroke into that
position of the AnsiString.
|
OK...but I don't know how to find the caret position..sigh
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Jul 21, 2004 5:14 pm Post subject: Re: Deriving TEdit (TEditNumber) |
|
|
"Matrix" <f_l_a_v_i_o.ba.ri.so.ne (AT) el_s_a_g (DOT) it> wrote
| Quote: | OK...but I don't know how to find the caret position.
|
Use the SelStart property.
Gambit
|
|
| Back to top |
|
 |
Yoann chaigneau Guest
|
Posted: Fri Jul 23, 2004 1:12 pm Post subject: Re: Deriving TEdit (TEditNumber) |
|
|
Hi,
Why don't you test the whole text of your edit in the onchage event ?
"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> a écrit dans le
message de news:40fea440 (AT) newsgroups (DOT) borland.com...
| Quote: |
"Matrix" <f_l_a_v_i_o.ba.ri.so.ne (AT) el_s_a_g (DOT) it> wrote in message
news:40fe316e$2 (AT) newsgroups (DOT) borland.com...
OK...but I don't know how to find the caret position.
Use the SelStart property.
Gambit
|
|
|
| Back to top |
|
 |
|