Solved

How to use a Masked Edit?

Posted on 2006-11-19
11
775 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

813 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

17 Experts available now in Live!

Get 1:1 Help Now