Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

MaskEdit Builder C++

Ostatnio zmodyfikowano 2014-09-09 20:58
Autor Wiadomość
Kefirek
Temat założony przez niniejszego użytkownika
MaskEdit Builder C++
» 2014-09-01 20:15:45
Witam

W MaskEdit użytkownik programu wprowadza 9 cyfr. Po wprowadzeniu mniejszej ilości cyfr i przejściu do kliknięcia button'a program pokazuje komunikat:
 Invalid input value. Use escape key to abandon changes.
Chciałbym zastąpić ten komunikat swoim własnym np ShowMessage("Wprowadzono za mało znaków.!!!").
Próbowałem przechwycić ten wyjątek try catch on Exit event  maskEdit, ale nie zadziałało.
Poniżej przedstawiam fragment kodu:
C/C++
void __fastcall TfrmKlient::medtKontaktExit( TObject * Sender )
{
    try
    {
        Klient->kontaktKlient = this->medtKontakt->Text.ToInt();
       
    }
    catch( EDBEditError * )
    {
        ShowMessage( "Wprowadź poprawne dane!!!" );
        this->medtKontakt->Text = "";
        this->medtKontakt->SetFocus();
    }
}
Pozdrawiam
P-116515
Monika90
» 2014-09-01 23:10:56
To w tym Builderze się łapie wyjatki przez wskaźnik, a nie normalnie?
P-116547
Kefirek
Temat założony przez niniejszego użytkownika
» 2014-09-02 18:17:41
Program się kompiluje z tym wskaźnikiem, więc chyba dobrze jest. Zamieniłem wskaźnik na referencję też się skompilowało, ale nic to nie zmienia...........
Pozdrawiam
P-116559
Monika90
» 2014-09-02 19:32:43
Czy jesteś pewien że ta funkcja w ogóle jest wywoływana?
Możesz wstawić na początku ShowMessage("OnExit"); żeby to sprawdzić.

Spróbuj wyłapywać wyjątek za pomocą catch (...) żeby się upewnić że w ogóle jakiś jest rzucany.
P-116560
Kefirek
Temat założony przez niniejszego użytkownika
» 2014-09-02 20:08:54
Umieściłem ShowMessage("OnExit"); zaraz na poczatku funkcji przed blokiem try.
......i wygląda na to, że exception EDBEditError Invalid input value jest wywoływany pierwszy przed event'em OnExit maskedit...........
Poniżej zamieszczam co mi się udało znaleźć- może pomoże to rozwikłać to zadanie.

z http://www.yevol.com/bcb/Lesson24.htm

MaskEdit Events

The main event of the MaskEdit control occurs when the content of the control has been altered. The compiler takes care of validating the characters and symbols while the user is editing the edit box. When the user has finished and presses Enter or Tab to possibly shift the focus to another control, a notification is sent to the operating system. If the value entered in the control does not conform to the EditMask property, an error is thrown and the application may stop responding. For this reason, you should use the MaskEdit control only when appropriately needed; or you should write an event handler or function that would deal with errors of this control.

Pozdrawiam
P-116563
Monika90
» 2014-09-02 22:22:26
Jest mało prawdopodobne byś uzyskał pomoc na tutejszym forum, bo tu nikt nie używa Buildera. Zapytaj na jakimś forum Delphi.
P-116567
Kefirek
Temat założony przez niniejszego użytkownika
» 2014-09-06 15:14:28
ValidateEdit attempts to validate the EditText after each keystroke, and when the user attempts to leave the masked edit field. If the EditText does not match the specifications of the EditMask, ValidateEdit calls ValidateError to raise an exception, and returns the cursor to the first position where the EditText did not comply with the EditMask.
Dzięki for Monika90
P-116674
Kefirek
Temat założony przez niniejszego użytkownika
» 2014-09-09 20:58:11
W rezultacie zrezygnowałem z MaskEdit na rzecz Edit i ustawiłem w Edit maxlenght na oczekiwaną ilość znaków. Następnie konwersja z Ansi String na int:
C/C++
int x = StrToIntDef( medtKontakt->Text, - 1 );
if( x == - 1 || medtKontakt->Text.Length() < 9 )
{
    ShowMessage( "Wprowadź 9 - cio cyfrowy numer telefonu!!!." );
    medtKontakt->Text = "";
    medtKontakt->SetFocus();
}
[ \c pp ]
P-116822
« 1 »
  Strona 1 z 1