Using a barcode scanner with Delphi

I am developing a POS (pet project) and I am considering adding a barcode scanner to track sales faster. I do not have a scanner at the moment with me, and I would like to ask a few questions, as I am a bit stuck.

On the sales screen, my initial idea was to have a TEdit component, and when a person scans a product, he fills the TEdit line with a line. Now the problem that I am facing is that I want to make TEdit invisible so that the person does not see this. But once you make TEdit invisible, you cannot focus on it so that the plan cannot work.

So can anyone suggest what I can use to β€œcapture” a scanned line? How to make a component listen and wait for a scanner? I assume that the scanner will look like a regular keyboard event, such as a down or up button.

+4
source share
4 answers

You can use TEdit with a height and width of 0 so that it does not appear and makes sure that it focuses when scanning a barcode.

+3
source

Here's the KeyPreview property on TForm. Set to true, so all keystrokes are processed in a form first before the controls.

Delphi keyboard processing article: http://delphi.about.com/od/objectpascalide/a/keyboard_events.htm

Related SO question: How does KeyPreview Delphi work?

+6
source

What I did was use KeyPreview to monitor for a function key, such as F9, for which the barcode scanner is set to prefix scanning. When this is received, I will open a dialog with one edit box and an OK button. Then it receives the rest of the barcode information, and the scanner finishes recording with the Enter key. Then I can determine the purpose of the scanned data (in my case, one type begins with a prefix), and then puts the data in the corresponding field in my main form.

I chose F9 because it seems to be inert in most applications, so you can use the scanner in other ways, but I support other keys for flexibility. My application also has a scanner verification mode, where it shows the keys sent.

+5
source

You can also put TEdit outside the visible window by setting the properties of the Top and Left component to something like -50. Then you can set the focus on it, like a regular visible TEdit block, but it will be invisible to the user.

0
source

All Articles