Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to do the verification

Status
Not open for further replies.

beginner81

Programmer
Oct 27, 2003
44
MY


I'm havin some problem here in doin verification, hope ya guys can help..

Ok.. i'm currently doin a barcode scanning system.. let's say if the users
scan the value A156238954H5.. all i want is just only the 10 digit numbers from the
result that they r scanning to be display (this field is always havin 10 digit numbers and
some of the character)... so in this case the value to b display is 1562389545...

How bout if i want to the verification that a field can only accept 5 bytes data??
otherwise an error message will prompted out..

and finally, how bout if i want to accept only the integer value in certain field, and no
character allowed in the field (prompted a message if user key in the character value)..

thanks in advance..
 
ok... let's take it one step at a time.

first:
you can retrieve 10 chars starting from the first of a string using:
result := copy(string, 2, 10);

second:
by field you mean an Edit field or a variable? in the first case use a TMaskEdit (use as EditMask: !99999;1;_), in the second, the best way (in my opinion) is to use a property:
Code:
private
   editOfFive : string;
   procedure setEdit(str : string);
public
   property MyEdit : string read editOfFive write SetEdit;
then in implementation:
Code:
 procedure TForm1.setEdit(str : string);
begin
    if length(str) > 5 then 
       MessageDlg('String has a length greater than five', mtError, [mbOk], 0)
    else form1.editOfFive := str;
end;

third:
same as before, if you want it to be an Edit like field, use TMaskEdit (though you won't be able to show error messages). If you want to show errors, and use an Edit like field, use the OnKeyDown property of the edit field to check each key (check the ord(Key) to be between 30 and 39, 48 and 57 - for numeric keys) and in case it's outside the interval, show an error message and supress the caracter from the field (
Code:
form1.Edit1.Text := copy(form1.Edit1.Text, 0, length(form1.Edit1.Text)-1);
). If your 'field' is a variable, use the property example from number two combined with the checking of each character from here to see if they're all numerals.
 
Ermm.. i think u misundestood me..
For case 1:
Assuming we don't know where the first numberic start.. i mean the first number can b start anywhere.. so all i want is just the numberic value within the string (P/S : each of the string hav 10 numeric number, with the mix of some character.. the clients doing this to encrypted the data)..

thanks for case 2 and case 3.. but do i hav other ways instead of using the TMaskEdit ?? cos i'd put all the component onto the form, it will b troublesome for me to change it whole over again... (P/s: All i'd mentioned is EditField)..


anyway, thanks very very much in helping me doing this project.. it's appreciated..
 
for the first case, you need to make a function that passes the string and returns the integer values within:

Code:
function TForm1.parseStr(str : string) : integer;
var
i : integer;
testChar : Char;
res : string;
begin
    res := '';
    for i:=0 to Length(str)-1 do
    begin
       testChar := str[i];
       if (ord(testChar) < 39) and (ord(testChar) > 30) then res := res + testChar;
    end;
    result := strToInt(res);
end;

now you just call the function with the string as param and use the result as the number you're looking for.

for two and three, you can set the masks at runtime if you want. just take a look at the help. or, use the case with the OnKeyDown event I described before.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top