Solved

How to use a Masked Edit?

Posted on 2006-11-19
11
766 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

15 Experts available now in Live!

Get 1:1 Help Now