Recent

Author Topic: [TMaskEdit] Edit or EditText  (Read 15399 times)

bdexterholland

  • Jr. Member
  • **
  • Posts: 65
  • uh?
[TMaskEdit] Edit or EditText
« on: December 06, 2011, 03:37:51 pm »
Hi folks!

Which property should i use to get the real typed text on a TMaskEdit, Edit or EditText?

[sleep .....]

Bart

  • Hero Member
  • *****
  • Posts: 5706
    • Bart en Mariska's Webstek
Re: [TMaskEdit] Edit or EditText
« Reply #1 on: December 06, 2011, 11:26:31 pm »
That all depends on what you mean by "real typed text".

EditText holds the text as you see it in the control, including the character used as spacechar (by default an underscore ('_')).
Text is the text with SpaceChar replaced with spaces (#32) and depending if Masknosave is specified in the mask all maskliterals are removed and the text is trimmed either left or right (again depending on the editmask).

See the source of maskedit.pp.

Example:

Code: [Select]
  Maskedit1.EditMask := '999.999.999.999;1;_';  //mask for IP-address perhaps?

Now if you type 128.254.192.1 in the control then
Text will be '128.254.192.1  '
EditText will be '128.254.192.1__'

Bart


bdexterholland

  • Jr. Member
  • **
  • Posts: 65
  • uh?
Re: [TMaskEdit] Edit or EditText
« Reply #2 on: December 07, 2011, 02:12:09 am »
as you said, it becames usefull for IP address but i wanna use it for personal documents.

i've created a mask 000.000.000-00;0;_ but i don't wanna get all mask chars, only the user's typed chars. Today, with my difficult to understand how it works, i create a function that returns only the numbers of the text. It's something like this:
Code: [Select]
Function RemoveUnecessaryCharsFromCPF(CPF : String) : String;
var
  aux : string;
  i : Integer;
begin
  aux := EmptyStr;
  for i:= 1 to length(CPF) do
    if (CPF[i] in ['0'..'9'] then
      Aux := Aux + CPF[i];
  Result := Aux;
end;
Is there any way to make MaskEdit return the text as i need, making unecessary to use this function?
[sleep .....]

Bart

  • Hero Member
  • *****
  • Posts: 5706
    • Bart en Mariska's Webstek
Re: [TMaskEdit] Edit or EditText
« Reply #3 on: December 07, 2011, 02:29:13 pm »
You can use a mask like '!999.999.999.999;0;_'

Now Text will hold only the numbers (and spaces between numers if they exist), without the periods, and left-trimmed (maybe right-trimmed, I didn't test, and I don't know by heart).
Just try playing around with different editmasks and see how Text and EditText behave.

I'll attach a sample MaskEdit test suite I use for development.
Just play with it.

For your purpose, in the end you may end up not using a maskedit at all.

Bart

bdexterholland

  • Jr. Member
  • **
  • Posts: 65
  • uh?
Re: [TMaskEdit] Edit or EditText
« Reply #4 on: December 07, 2011, 03:42:41 pm »
thanks! it solved my issue...
[sleep .....]

 

TinyPortal © 2005-2018