不需任何軟件在掃條碼的時候聽到一聲響時就相當於按的一個回車鍵 你可在Edit控件的Edit1KeyPress事件中寫代碼: procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then begin //事件代碼 end; end; 就這麼簡單
条形码扫描仪: 1、键盘口:扫描进来的数据会自动输入到获得焦点的控件上,而且是以#13结尾 可以用来判断结束标志 2、串口: 可以用SPCOMM控件: procedure TfrmMain.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word); var sBarcode: String; s: string; i: Integer; //CordList: TStringList; iLen: Integer; begin //CordList:= TStringList.Create; SetLength(s, BufferLength); Move(Buffer^, pchar(s)^, BufferLength); //CordList.Add(s); Memo1.Lines.Add(S); Memo1.Invalidate; sBarcode:= ''; for i := 0 to memo1.Lines.Count - 1 do begin if Length(memo1.Lines[i]) > 0 then sBarcode:= sBarcode + memo1.Lines[i] else begin bEnter:= True; Memo1.Clear; end; end; if bEnter then begin iLen:= Length(sBarcode); if iLen = 32 then begin if frmShowInfo_Barcode32.ShowInformation(sBarcode) then frmShowInfo_Barcode32.ShowModal else frmInformation.ShowModal; end else if iLen = 13 then ///showmessage(inttostr(Length(sBarcode))) begin if frmShowInfo_Barcode13.ShowInformation(sBarcode) then frmShowInfo_Barcode13.ShowModal else frmInformation.ShowModal; end else frmInformation.ShowModal; bEnter:= false; end; {for i := 0 to memo1.Lines.Count - 1 do begin if Length(Memo1.Lines[i]) > 0 then sBarcord:= sBarcord + memo1.Lines[i]; if Length(sBarcord) = 32 then if not bEnter then begin bEnter:= true; Memo1.Clear; if not Assigned(frmShowInfo_Barcode32) then frmShowInfo_Barcode32:= TfrmShowInfo_Barcode32.Create(self); if frmShowInfo_Barcode32.ShowInfomation(sBarcord) then frmShowInfo_Barcode32.ShowModal else begin frmInformation.ShowModal; bEnter:= False; end; end else if Length(sBarcord) = 13 then if not bEnter then begin bEnter:= true; Memo1.Clear; if frmShowInfo_Barcode13.ShowInformation(sBarcord) then frmShowInfo_Barcode13.ShowInformation(sBarcord) else begin frmInformation.ShowModal; bEnter:= False; end; end; end; //end for } //showmessage(sBarCord); //frmShowInfo_Barcode32.teBarcode32.text:= sBarCord; end;
相当于键盘按键+回车,就这么简单http://lysoft.7u7.net
你可在Edit控件的Edit1KeyPress事件中寫代碼:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
//事件代碼
end;
end;
就這麼簡單
PS2就简单死了,就是相当于键盘输入。串口的你注意一下它的波特率,较验,停止位。,数据位
1、键盘口:扫描进来的数据会自动输入到获得焦点的控件上,而且是以#13结尾
可以用来判断结束标志
2、串口: 可以用SPCOMM控件:
procedure TfrmMain.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var sBarcode: String;
s: string;
i: Integer;
//CordList: TStringList;
iLen: Integer;
begin
//CordList:= TStringList.Create; SetLength(s, BufferLength);
Move(Buffer^, pchar(s)^, BufferLength); //CordList.Add(s);
Memo1.Lines.Add(S);
Memo1.Invalidate;
sBarcode:= '';
for i := 0 to memo1.Lines.Count - 1 do
begin
if Length(memo1.Lines[i]) > 0 then
sBarcode:= sBarcode + memo1.Lines[i]
else
begin
bEnter:= True;
Memo1.Clear;
end;
end;
if bEnter then
begin
iLen:= Length(sBarcode);
if iLen = 32 then
begin
if frmShowInfo_Barcode32.ShowInformation(sBarcode) then
frmShowInfo_Barcode32.ShowModal
else
frmInformation.ShowModal;
end
else if iLen = 13 then ///showmessage(inttostr(Length(sBarcode)))
begin
if frmShowInfo_Barcode13.ShowInformation(sBarcode) then
frmShowInfo_Barcode13.ShowModal
else
frmInformation.ShowModal;
end
else
frmInformation.ShowModal; bEnter:= false;
end;
{for i := 0 to memo1.Lines.Count - 1 do
begin
if Length(Memo1.Lines[i]) > 0 then
sBarcord:= sBarcord + memo1.Lines[i]; if Length(sBarcord) = 32 then
if not bEnter then
begin
bEnter:= true;
Memo1.Clear;
if not Assigned(frmShowInfo_Barcode32) then
frmShowInfo_Barcode32:= TfrmShowInfo_Barcode32.Create(self);
if frmShowInfo_Barcode32.ShowInfomation(sBarcord) then
frmShowInfo_Barcode32.ShowModal
else
begin
frmInformation.ShowModal;
bEnter:= False;
end;
end
else if Length(sBarcord) = 13 then
if not bEnter then
begin
bEnter:= true;
Memo1.Clear; if frmShowInfo_Barcode13.ShowInformation(sBarcord) then
frmShowInfo_Barcode13.ShowInformation(sBarcord)
else
begin
frmInformation.ShowModal;
bEnter:= False;
end;
end;
end; //end for }
//showmessage(sBarCord);
//frmShowInfo_Barcode32.teBarcode32.text:= sBarCord;
end;