1

I have a small problem with my application. I have a new product adding dialog window. There's a barcode textbox on the form. And two buttons - "Cancel" with Cancel property True and "Save" with Default property True.

Now if I'm making my barcode textbox active and scanning barcode with barcode scanner it adds newline character in the end of the barcode. And there's the problem - it submits the form automatically, because "Save" button accepts ENTER as a submit key.

How can I avoid that scanning barcode and there's newline character at the end, that it does not affect form's default button?

Thanks in advance!

evilone
  • 22,410
  • 7
  • 80
  • 107

3 Answers3

4

A barcode scanner, in its simplest form, appears to the OS as just another keyboard. Since you want to ignore when the barcode scanner sends the signal for Enter, but you want to accept it when the user presses the same key on the "real" keyboard, you'll need to distinguish between multiple keyboards.

Community
  • 1
  • 1
Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
2

You can use OnEnter and OnExit event on your textbox to set Default of Save button. I don't know if your "barcode textbox" is some kind of special component but this works for a TEdit.

procedure TForm4.Edit1Enter(Sender: TObject);
begin
    ButtonSave.Default := False;
end;

procedure TForm4.Edit1Exit(Sender: TObject);
begin
    ButtonSave.Default := True;
end;
Mikael Eriksson
  • 136,425
  • 22
  • 210
  • 281
  • Ok, this works, but there's one problem. What if this is final editbox that user enters data to. Then he adds barcode (by hand or with scanner) and then wants to submit the form by pressing ENTER. Then it don't work. I think maybe I can use some help of timers somehow? – evilone Mar 10 '11 at 07:54
1

If you are using Symbol scanners I know you can use the manual and change the suffix character to none. By default, most Symbol scanners are configured to automatically add a return character to the data....

Jeremy Conley
  • 924
  • 5
  • 6
  • 1
    This doesn't solve my problem, because clients who will be using that program, don't know how to configure barcode scanner – evilone Mar 10 '11 at 06:54
  • 1
    FWIW, with my software I supply a PDF for various scanners which sets them up so that they will work optimally. However, you should also account for the default settings. – mj2008 Mar 10 '11 at 10:29
  • Sorry...that's my best solution since I don't know Delphi. Since the scanner config is just scanning one or two barcodes, that is what I've done before: cropped them out of the email, printed them (or emailed) and told people to scan these to fix their problem. :) – Jeremy Conley Mar 10 '11 at 18:34
  • +1. I don't think it's unreasonable to require customers to have properly configured hardware. – Rob Kennedy Mar 10 '11 at 19:09