Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi Forms / combo box / keypreview

Status
Not open for further replies.

awarnica

Programmer
Jan 16, 2003
78
CA
I have a form, with Keypreview = true;

I am capturing barcodes through a keyboard wedge.

I have a panel which displays the keypresses as they occur.

So if I type / scan '1234', the panel displays '1234'

But if I put a combo box on the form, and put focus to the combo box, then type '1234', the panel displays '11223344'

I have stepped through the code and it seems that I am hitting the OnKeyPress event twice for each keypress.

If I replace the combo box with a listbox and set focus and type I do not get the problem.

Has anybody heard of this before? Any help is appreciated.

Andrew
 
i tried doing what you did but without a scanner but couldnt duplicate your result.

i would have to see the code to help any more.
maybe someone else may have an answer :) Aaron Taylor
John Mutch Electronics
 
The below works for a listbox, but if i drop a combo box on the form, i get the duplicate numbers. Note that the style of combo box is csDropDownList, not the default csDropDown


procedure TfrmTubFeeding.FormKeyPress(Sender: TObject; var Key: Char);
begin
if (Ord(Key) = 27) then
begin
Close;
exit;
end;

UpdateInfo('Reading Barcode: ' + strKeyPressBuffer, clGreen, lbInfo);

...more code down here

end;

// Use: UpdateInfo(a, b, c)
// Pre: a is a string message to be displayed on lbInfo
// b is the color of the message (clRed or clGreen)
// c is the name of the listbox to be updated
// Post: Displays a message to the user that is of the given color. Green is used
// to indicate that everything is working, Red indicated an error message
procedure UpdateInfo(const pstrIn: string; pcol: TColor; var plbListbox: TListBox);
var
ldLength: integer;
begin
plbListbox.Font.Color := pcol;
plbListBox.Clear;
//find width of listbox for the particular form
ldLength := Round(plbListBox.Width/16);
//if length of string is greater than the width of the listbox, add a second line
if Length(pstrIn) > ldLength then begin
plbListbox.Items.Add(Copy(pstrIn, 1, ldLength));
plbListbox.Items.Add(Copy(pstrIn, ldLength+1, (Length(pstrIn)-ldLength + 1)) + '...');
end else if Trim(pstrIn) = '' then
plbListBox.Items.Add('')
else
plbListbox.Items.Add(pstrIn + '...');
DoEvents;
end;
 
I do not want the user to enter different choices, thus the csDropDownList. They should only be able to choose one of the options populated on the open of the form.

This seems to be the problem, when I use a csDropDown I don't get the double numbers.


Andrew
 
I have had this problem recently but never figured it out, I cheated and used FormKeyDown instead, for some reason this worked a lot better but not sure it this is relevant in your case.

Also may sound stupid but in some cases it helps to restart windows as working with this kind of process can some times throw it out. Had fun with that one ;-)

Sorry, probably not much use.

JW.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top