Solved

How to use a Masked Edit?

Posted on 2006-11-19
11
769 Views
Last Modified: 2008-02-20
Hya Folks!

I'd like to use the jvMaskEdit from the Jedi VCL. Now I would like to force standard Microsoft serial numbers so something like GWH28-DGCMP-and so on and so on until we have 25 characters and numbers nicely kept from eachother by a - sign.

Any ideas to achieve this?

Kind regards,

Paul ;-)

Ps working samples do the trick
0
Comment
Question by:PeterdeB
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 11

Accepted Solution

by:
Goodangel Matope earned 500 total points
ID: 17976083
On the "editMask" property of your jvMaskEdit, use the following

AAAA\-AAAA\-AAAA\-AAAA\-AAAA

I am logged into my linux box, but the mask property can be used to enforce stuff exactly as you have pointed out. I hope I have remembered this mask stuff properly though.

0
 
LVL 11

Expert Comment

by:Goodangel Matope
ID: 17976086
Confirm with EditMask in delphi help to ensure I have not provided poisonously wrong data
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17976117
Goodangel is correct. You might also want to set
CharCase to ecUpperCase;
0
 
LVL 28

Expert Comment

by:TName
ID: 17976230
Hi,
You don't really need a Mask edit. You could try something like this with a regular TEdit:
(haven't tested it thoroughly though. Should be tested...)


procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
len:Integer;
var NumChar : set of char;
s:String;
begin
 NumChar := ['0'..'9','a'..'z','A'..'Z'];

 {or use this if lowercase shouldn't be accepted at all (not even converted to uppercase)}
 //NumChar := ['0'..'9','A'..'Z'];

 len:=Length(TEdit(Sender).Text);
 if len>0 then
   Inc(Len);


 if Key <> Char(VK_BACK) then
   if (len=0) and (not (Key in NumChar)) or (len>23) then begin
      Key := #0;
      Exit;
   end
   else begin
           if ((len mod 6=0) and (len>0)) then begin
              if (Key <>'-') then
                Key := #0;
           end
           else
           if (not (Key in NumChar)) then
                Key := #0;
 end;

 TEdit(Sender).Text:=UpperCase(TEdit(Sender).Text); //If needed

end;
0
 
LVL 9

Expert Comment

by:bernani
ID: 17976238

Maybe also:

procedure TForm1.FormCreate(Sender: TObject);
begin
jvMaskEdit1.text:= '';
jvMaskEdit1.EditMask:= '>AAAAA-AAAAA-AAAAA-AAAAA-AAAAA';
jvMaskEdit1.AutoSelect:= False;
end;

// sign > to force uppercase
// A : use of alphanumeric chars
//- no special meaning, used as separator

also like this:

Procedure SplitString(const Source: String; const Delimiter: String; const Dest: TStringlist);
var
  count: Integer;
  LStartpos, LEndpos, LSourceLength: Integer;
  LDelimiterLength : Integer;
begin
  Dest.Clear;
  count := 1;
  LStartpos := 0;
  LEndpos := 0;
  LSourcelength := length(Source);
  LDelimiterLength := Length(Delimiter);
  while count <= LSourcelength do
  begin
    if copy(Source, count, LDelimiterLength) = Delimiter then
    begin
      LEndpos := count;
      dest.Add(copy(Source, LStartpos + 1, LEndpos - LStartpos - 1));
      LStartpos := count + LDelimiterLength - 1;
      inc(count,LDelimiterLength);
    end else
    begin
      inc(count);
    end;
  end;
  if LEndPos <> Count - LDelimiterLength then
    dest.Add(copy(Source, LStartpos + 1, count - LStartpos - 1));
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  ToSplit: String;
  SL: TStringlist;
  a, b,c,d,e : string;
begin
  ToSplit := 'ERTZE|HGTYU|09GYT|HYTRF|YS45E';
  Try
  SL := TStringlist.Create;
  splitString(ToSplit, '|', SL);
  a:= SL.Strings[0]+'-';
  b:= SL.Strings[1]+'-';
  c:= SL.Strings[2]+'-';
  d:= SL.Strings[3]+'-';
  e:= SL.Strings[4];
  //showmessage(a +' '+ b + ' ' + c + ' '+ d + ' '+ e);
  jvMaskEdit1.text:= a+b+c+d+e;
  Finally
  SL.Free;
  End;
end;


You can store the mask in the file *.dem use by the jvcl.
This files store the different mask for each country.

______________________________________________

Hope this help.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 28

Expert Comment

by:TName
ID: 17976243
You don't need the "Exit", I just forgot it there :/
0
 

Author Comment

by:PeterdeB
ID: 17976247
Hi my dear friends!

It works GoodAngel...it only required an extra A > AAAAA\-AAAAA ...obviously.

Thanks a lot!

TheRealLoki > thanks for your tip! It was the only thing I had taken care off already but thanks anyway!

TName > thanks for your code...I deliberately chose out the Masked edit since I prefer placing some uncommon object on my form to having to code all myself. The less code in my project > the less complex it becomes for me. Nevertheless it's cool that you can code an edit to have it behave like a masked one!

Kind regards,

Paul ;-)
0
 

Author Comment

by:PeterdeB
ID: 17976261
And thanks bernani ofcourse! I only just noticed your reply after I had replied and returned to my Outlook inbox.

Kind regards,

Paul
0
 
LVL 28

Expert Comment

by:TName
ID: 17976275
Well, I'm glad you found the solution.  :)
Just for the record, a somewhat cleaned up version:



procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
len:Integer;
var NumChar : set of char;
begin
 NumChar := ['0'..'9','a'..'z','A'..'Z'];
 if (Key in ['a'..'z']) then
   Key:=UpperCase(Key)[1];

 len:=Length(TEdit(Sender).Text);
 if len>0 then
   Inc(Len);
 if Key <> Char(VK_BACK) then
   if (len=0) and (not (Key in NumChar)) or (len>23) then
      Key := #0
   else begin
           if ((len mod 6=0) and (len>0)) then begin
              if (Key <>'-') then
                Key := #0;
           end
           else
           if (not (Key in NumChar)) then
                Key := #0;
 end;
end;
0
 
LVL 28

Expert Comment

by:TName
ID: 17976284
NumChar := ['0'..'9', 'A'..'Z'];
0
 

Author Comment

by:PeterdeB
ID: 17977312
TName > next step woudl be to create a masked edit from a regular edit so we have a component we could install?

Kind regards,

Paul :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now