Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to use a Masked Edit?

Posted on 2006-11-19
11
Medium Priority
?
804 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 11

Accepted Solution

by:
Goodangel Matope earned 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

636 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