Solved

How to use a Masked Edit?

Posted on 2006-11-19
11
788 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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