Board index » delphi » Stuffing Keyboard From Listbox To Edit?

Stuffing Keyboard From Listbox To Edit?

Hi,

I'm looking for ideas on how to get the information typed on the keyboard
into an edit control. I'm putting together a combination of edit control and
listbox for a custom locator combobox. I've got everything working except
for when the listbox has the focus and the users type in character for
search on. I tried stuffing the keyboard characters into the edit control's
text property, but when the user presses the backspace key the edit control
doesn't backspace - it gets a $08 inserted in to the text.

Is there a better way to send keyboard input from the listbox to the edit
control using Windows messages instead? Would this make the edit control
react to non-text keys like backspace correctly? Can someone point out what
message to use and how to use it?

-Andy
andyw...@ix.netcom.com

 

Re:Stuffing Keyboard From Listbox To Edit?


Andy,

provide message handlers for WM_KEYDOWN, WM_CHAR and WM_KEYUP for your listbox
and send the messages on to the edit control via SendMessage or Perform.

Peter Below (TeamB)  100113.1...@compuserve.com)

Quote
In article <69uhds$h...@forums.borland.com>, Andy Weed wrote:
> From: "Andy Weed" <andyw...@ix.netcom.com>
> Newsgroups: borland.public.delphi.vcl.components.using
> Subject: Stuffing Keyboard From Listbox To Edit?
> Date: Sun, 18 Jan 1998 19:39:13 -0800

> Hi,

> I'm looking for ideas on how to get the information typed on the keyboard
> into an edit control. I'm putting together a combination of edit control and
> listbox for a custom locator combobox. I've got everything working except
> for when the listbox has the focus and the users type in character for
> search on. I tried stuffing the keyboard characters into the edit control's
> text property, but when the user presses the backspace key the edit control
> doesn't backspace - it gets a $08 inserted in to the text.

> Is there a better way to send keyboard input from the listbox to the edit
> control using Windows messages instead? Would this make the edit control
> react to non-text keys like backspace correctly? Can someone point out what
> message to use and how to use it?

> -Andy
> andyw...@ix.netcom.com

Re:Stuffing Keyboard From Listbox To Edit?


Quote
>provide message handlers for WM_KEYDOWN, WM_CHAR and WM_KEYUP for your
listbox
>and send the messages on to the edit control via SendMessage or Perform.

Can you cive me a few pointers on how to implement the above? Do I have to
create a new listbox component or can I put the message handlers in the form
that contains my edit control and listbox.

-Andy
andyw...@ix.netcom.com

Re:Stuffing Keyboard From Listbox To Edit?


Quote
In article <6a31rg$j2...@forums.borland.com>, Andy Weed wrote:
> Can you cive me a few pointers on how to implement the above? Do I have to
> create a new listbox component or can I put the message handlers in the form
> that contains my edit control and listbox.

Andy,

if you want to have your listbox/edit combination perform as a unit from the
component users view both should be encapsulated into a single component and
that would indeed best be done with a derivative of TListbox that has handlers
for the messages i mentioned. For a quick&dirty solution one could tie a
normal TEdit and TListbox together with event handlers on the form level, but
it would be ugly stuff, something like this (untested!):

  Function IsListboxKey(Key: Word): Boolean;
  Begin
    case Key Of
      VK_UP, VK_DOWN, VK_HOME, VK_END, VK_PRIOR, VK_NEXT:
        Result := True
    Else
      Result := False
    End;
  End;  

  //listbox OnKeyDown, OnKeyUp and OnKeyPress handlers:
  Procedure TForm1.Listbox1KeyDown( Sender: TObject;
     Var Key: Word; Shift: TShiftState );
  Begin
    If not ((Alt In Shift) or IsListboxKey(Key)) Then Begin
      PostMessage( edit1.handle, WM_KEYDOWN, Key,
                   MakeLong( 0, MapVirtualkey( Key, 0)));
      Key := 0;
    End;  
  End;                  

  Procedure TForm1.Listbox1KeyUp( Sender: TObject;
     Var Key: Word; Shift: TShiftState );
  Begin
    If not ((Alt In Shift) or IsListboxKey(Key)) Then Begin
      PostMessage( edit1.handle, WM_KEYDOWN, Key,
                   MakeLong( 1, MapVirtualkey( Key, 0) or $C000));
      Key := 0;
    End;  
  End;                  

  Procedure TForm1.Listbox1KeyPress( Sender: TObject;
     Var Key: Char; Shift: TShiftState );
  Begin
    If not (Alt In Shift) Then
      Key := #0;
  End;

Peter Below (TeamB)  100113.1...@compuserve.com)

Other Threads