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 barcod开发者_如何学Ce 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!
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.
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;
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....
精彩评论