4

I'm developing a POS (pet project) and I'm thinking of adding a bar code scanner to capture the sales faster. I do not have a scanner at the moment with me, and would like to ask some questions, as I'm stuck a bit.

On the sales screen my initial idea was to have an TEdit component and when a person scans the product it would fill the TEdit with the string. Now the problem I'm encountering is that I want to make the TEdit invisible so that the person does not see it. But once you make the TEdit invisible, you cannot set focus on it, so that plan cannot work.

So can anyone suggest what I can use to "capture" the scanned string? How would I make the component to listen and wait for the scanner? I assume that the scanner would be like a normal keyboard event, like button down or up.

Harriv
  • 6,029
  • 6
  • 44
  • 76
Japster
  • 985
  • 6
  • 19
  • 38
  • 2
    Barcode scanners usually appear to send keystrokes, so you can _handle_ it in the same way you handle the keyboard. If you don't want to have a visible Edit, you can handle the keystrokes at the form level with the OnKey Up/Down/Press events. – jachguate Feb 26 '13 at 22:37
  • I understand, but what will I use to capture the string of the barcode as soon as there is a OnKey event. With an TEdit it is easy as I could just let the string appear in the TEdit and take it from there. – Japster Feb 27 '13 at 16:19
  • It turns out question has little to do with barcode scanner, but more with "how to receive text with no focused control". Is that right? – Kromster Feb 28 '13 at 08:06
  • @Krom Yes that would be a much better question. – Japster Feb 28 '13 at 13:30
  • 1
    There are some barcode scanners which can bypass the "keyboard wedge" and you can connect your program directly to the barcode scanner device, which appears as a serial port to your program. I find this superior to HID/keyboard wedge for SOME applications. Just putting the info out there for you. – Warren P Mar 01 '13 at 01:06

4 Answers4

6

There's KeyPreview property on TForm. Set it to true, so all key presses are processed by form first before controls.

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

Related SO question: How does Delphi's KeyPreview work?

Community
  • 1
  • 1
Harriv
  • 6,029
  • 6
  • 44
  • 76
6

What I have done is use the KeyPreview to monitor for a function key like F9 which the bar code scanner is set to prefix scans with. When this is received, I pop up a dialog with a single edit box and OK button. This then receives the rest of the barcode information, and the scanner ends the entry with the Enter key. I can then determine the purpose of the scanned data (in my case, one type starts with a prefix) and then put the data into the appropriate field on my main form.

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

mj2008
  • 6,647
  • 2
  • 38
  • 56
3

You can use a TEdit with a height and width of 0 so it won't appears and make sure it get focused when you scan your barcode.

Epiphanyx
  • 46
  • 1
0

You can also place the TEdit outside of the visible window, setting the component's Top and Left properties to something like -50. You can then set focus to it just like a regular visible TEdit box, but it will be invisible to the user.