Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

USB Barcode Reader and KeyPress

412 views
Skip to first unread message

Tom Russell

unread,
Jul 30, 2007, 2:07:42 PM7/30/07
to

I am trying to capture the input from a barcode reader with my main form and then call up a data entry form with the text from the barcode reader. I can call up the form using the keypress for the most part but cant seem to focus the editfield I need to get the input.

Any suggestions or ideas?


Thanks,


Tom

Peter Below (TeamB)

unread,
Jul 31, 2007, 1:17:00 AM7/31/07
to
Tom Russell wrote:

>
> I am trying to capture the input from a barcode reader with my main
> form and then call up a data entry form with the text from the
> barcode reader. I can call up the form using the keypress for the
> most part but cant seem to focus the editfield I need to get the
> input.
>

Set the forms Activecontrol property to the control you want to get
focus when the form is shown.

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com

Tom Russell

unread,
Jul 31, 2007, 6:22:27 AM7/31/07
to

Pete,

This is my keypress event code for my main form:

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
Var
f: TForm3;
begin
f := TForm3.Create(self);
try
f.ActiveControl := f.calid;
f.ShowModal;
finally
f.Free;
end;
end;

calid is a dbedit but it still wont receive the focus I need to capture the barcode reader. Is there a way to get the info from the barcode reader in another way?

Thanks,

Tom

Peter Below (TeamB)

unread,
Jul 31, 2007, 12:55:55 PM7/31/07
to
Tom Russell wrote:

>
> Pete,
>
> This is my keypress event code for my main form:
>
> procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
> Var
> f: TForm3;
> begin
> f := TForm3.Create(self);
> try
> f.ActiveControl := f.calid;
> f.ShowModal;
> finally
> f.Free;
> end;
> end;
>
> calid is a dbedit but it still wont receive the focus I need to
> capture the barcode reader.

How do you determine that? If you start typing after the form comes up,
does the input go into the calid control?

If your Keypress handler is triggered by the barcode readers first
character (the lead in sequence) the whole sequence of characters the
barcode reader produces will probably already be in the message queue,
and targeted at the control that had the focus in your form1, so when
the modal form comes up there are simply no more characters it can
receive.

> Is there a way to get the info from the barcode reader in another way?

Of course. The usual way is to make sure the form to receive the input
is visible and has the target control focused *before* the user starts
to scan the barcode. This has the added advantage that the user can
type in the barcode if the scanner fails to read it since it's damaged,
warped or whatever. A situation quite frequent in real life <g>.

An alternative would be to manually read the keyboard input messages
after your keypress handler has seen the lead-in sequence until you get
the terminator from the barcode reader. You would do this using a
classic PeekMessage loop, just do not dispatch the message but extract
the characters from the WM_CHAR message directly. You need to call
TranslateMessage for WM_KEYDOWN messages, otherwise the WM_CHAR
messages would not be created. Deriving a character directly from
WM_KEYDOWN is also possible but it is easier to let Windows do this
work.

0 new messages