Home > Back-end >  Consult an edit initials limit input problem
Consult an edit initials limit input problem

Time:09-26

Every BBS A great god, and I designed A scanning system of the input, want to ask, how to limit edit1 can enter the first letter for B, B, and digital, edit2 can only enter A, A, input error an error, then the attached code and interface, function complete for edit1 scanning under to enter signal has to jump to edit2, edit2 scan done to receive the scanning gun enter from the button to complete the entry, and jump edit1, the new one, the hope can get everybody's help thank you
 unit Unit1; 
Interface
USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Menus, SkinCaption, WinSkinData;
Type
TForm1=class (TForm)
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
Button2: TButton;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
MainMenu1: TMainMenu;
N1: TMenuItem;
SkinData1: TSkinData;
SkinCaption1:
Procedure Button2Click (Sender: TObject);
Procedure N1Click (Sender: TObject);
Procedure Edit1KeyPress (Sender: TObject; Var Key: Char);
Procedure Edit2KeyPress (Sender: TObject; Var Key: Char);

Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form1: TForm1;

Implementation

USES Unit2.

{$R *. DFM}

Procedure TForm1. Button2Click (Sender: TObject);
The begin
With adoquery1 do
The begin
The close;
SQL. Text:="insert into saomiao (hougai ziju) values (' ' '+ edit1. Text +' ' ', ' '+ edit2. Text +') '.
Execsql;
end;
end;

Procedure TForm1. N1Click (Sender: TObject);
The begin
Form2. Show;
end;

Procedure TForm1. Edit1KeyPress (Sender: TObject; Var Key: Char);
The begin
If 13 is the enter key=# 13 then//
The begin
Edit2. SetFocus;
end;
end;

Procedure TForm1. Edit2KeyPress (Sender: TObject; Var Key: Char);
The begin
If the key=# 13 then
The begin
Button2. Click;
Edit1. SetFocus;
end;
end;
End.

CodePudding user response:

Can input error an error prompt

CodePudding user response:

If not in [] then or to change it to judge the character length, if the lengh () length is 1, then the if... else... Bar code machine can set, if after the scan is complete and press enter

CodePudding user response:

Edit1 first character is B or B, followed by the Numbers: A12312412
Or the first character is B or B or digital,

Statement is not clear?

CodePudding user response:

refer to the second floor i_am_a_fish response:
if not in [] then or to change it to judge the character length, if the lengh () length is 1, then the if... else... Whether the machine can be set, barcode scanning is completed and the enter


Agree with the second floor in the OnChange event handling practices, supplement:
Procedure TForm1. Edit1Change (Sender: TObject);
The begin
If LowerCase (copy (edit1. Text, 1, 1)='a' then
//legal;
The else
//illegal;
end;

CodePudding user response:

4th floor has a problem is an error very frequently, that's because esau code into more than one character at a time, if the first character in the wrong, behind every character input error, so the 2nd floor method should be more reasonable, whether the input after enter legal, legal to edit2, illegal feedback error messages, to operate, or judgment in the exit event

CodePudding user response:

reference lyhoo163 reply: 3/f
Edit1 first character is B or B, followed by the Numbers: A12312412
Or the first character is B or B or digital,

Statement is not clear?

The first character is a or B B or a number

CodePudding user response:

Edit1 first character is A or A or digital
Edit2 first character is B or B or digital

1, can input as required;
After 2, request input, such as the way to delete first character, will empty characters,

So don't need, tip error, as long as the entry, conform to the specifications,
All the code is as follows:
 unit Unit1; 

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

Type
TForm1=class (TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
For: TButton;
Procedure Edit1KeyPress (Sender: TObject; Var Key: Char);
Procedure Edit2KeyPress (Sender: TObject; Var Key: Char);
Procedure Edit1Change (Sender: TObject);
Procedure Edit2Change (Sender: TObject);
Procedure Button1Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form1: TForm1;

Implementation

{$R *. DFM}

Procedure TForm1. Edit1KeyPress (Sender: TObject; Var Key: Char);
Var E: TEdit;
S: a string;
The begin
With Sender as TEdit do
The begin
E:=Sender as TEdit;
S:=e. ext.
If Length (S)=0 then
If not (key [in '0'... '9', 'A', 'A']) then
Key:=# 0;
end;
end;

Procedure TForm1. Edit2KeyPress (Sender: TObject; Var Key: Char);
Var E: TEdit;
S: a string;
The begin
With Sender as TEdit do
The begin
E:=Sender as TEdit;
S:=e. ext.
If Length (S)=0 then
If not (key [in '0'... '9', 'B', 'B']) then
Key:=# 0;
end;
end;

Procedure TForm1. Edit1Change (Sender: TObject);
Var E: TEdit;
S: a string;
Firstkey: Char;
The begin
With Sender as TEdit do
The begin
E:=Sender as TEdit;
S:=e. ext.
If Length (S) & gt; 0 then
The begin
Firstkey: [1]=S;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related