Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-10

How can i mask an input on dbedit? Maskedit not ready!

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Osvaldo Filho

Environment:

OS: Windows XP SP3
FPC: 2.2.4 and 2.3.1
Lazarus: 0.9.29 and 0.9.28.1

editmask: '000\.000\.000\-00;0;_'

Several errors:
- Text not mach with mask ...
- dbedit without mask: _________________ and when a clear (backspace) my mask apear.

Is there any other idea without editmask?

Thanks.

Reply by email

Bart
to Osvaldo Filho
Show quoted text 7 lines
editmask: '000\.000\.000\-00;0;_' Several errors: - Text not mach with mask ... - dbedit without mask: _________________ and when a clear (backspace) my mask apear.

Applying your mask to a MaksEdit gives me this text in the control "___.___.___-__"

Which is what I expect.

From maskedit.pp:

Bugs:
- If you place a TMaskEdit on a form and at designtime set the mask and leave the text in the control "invalid" (as in: will not validate) and the TMaskEdit
is the ActiveControl of the form, then before the form is displayed an exception will
be raised, because somehow DoExit is executed (which calls ValidateEdit) A bugreport on this behaviour is in Mantis: #0012877

Might this be the case?

If so, try setting the EditMask at runtime.

- Text not mach with mask ...

This text should only be shown __when the control looses focus__ and the text does not match the mask.

Bart

Reply by email

Bart
to Osvaldo Filho: Environment: OS: Windows XP SP3 FPC: 2.2.4 and 2.3.1 Lazarus: 0.9.29 and 0.9.28.1…

You can also try building the program with -dNOVALIDATEONEXIT, this will suppress the validating when the controll looses focus. You can do validating then by yourself

procedure SomeDBEditChange(Sender: TObject);
begin  ...
  try
    (Sender as TMaskEdit).ValidateEdit;
  except
    ShowMesage('Validation failed');
  end;
  ...
end;

Finallly, try r22053, where I fixed some minor bugs in TMaskEdit.

Bart

Reply by email

Bart
to Bart

There is also a bug there.

First:
When setting text, spaces are not translated to BlankChar ('_' by default)

Second:
In Delphi setting text behaves different in how it treats mask literals depending on wether MaskNoSave is defined in the mask.

Consider trying to set the following text:
'ABC EFGHIJK'

EditMask: '999.999' -> Text becomes "ABC.___"
(in fact it stops as soon as it encounters a literal that does not fit)

EditMask '999.999;0;_' -> Text becomes "ABC. EFGHIJK" Note that it just skips literals and goes on filling in the text, which is correct since all maskliterals are removed in GetText also. (Also note that the Text property now exceeds the length of the mask, and it cannot be corrected, which is a definite bug in my D3)

If you define ! in the Editmask along with MaskNosave, it fills text from the last character.

I will try and fix TCustomMaskEdit.SetText to
1. use FBlankChar for spaces in Text
2. handle FMaskSave = False to keep on filling after the occurrence of maskliterals

(You could post a bugreport on the bugtracker stating that setting MaskEdit.Text does not correctly handle MaskNoSave in EditMask. I'll assign that to me then, so I won't forget)

I have one question for you.
Do you have to use MaskNoSave in the EditMask?
Probably the database you're using is legacy and you can't alter, but if it's a new project consider not having MaskNoSave in your EditMask, since it is probably unsafe in Delphi (as my experiment above has shown).

One remark:

editmask: '000\.000\.000\-00;0;_'

There is no need to escape the period's or the hyphen, only predefined maskcharacters need to be escape in order to include them as a literal in the mask.

Bye,

Bart

Reply by email