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!

FormKeyDown with other component focused !?

Status
Not open for further replies.

Delphard

Programmer
Jul 22, 2004
144
RS
Form is switched in maximized/normal state on pressing SPACE. But...
When Form is created, Edit1 component has Focus (for some purposes). So, pressing SPACE actually change Form state, but "collateral damage" is that Edit1.Text Property is also changed.
I try this:

Code:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_SPACE then
    begin
      if self.WindowState = wsNormal then
        self.WindowState := wsMaximized
      else
        self.WindowState := wsNormal;

  Key := VK_LEFT;   {doesn't works!?}

//  Edit1.Clear;   {this also doesn't works!}
    end;
end;

but without result.

Any idea how to prevent Edit1.Text Property to be changed?
 
I think it's not a good idea to switch using 'space'.
Giovanni Caramia
 
You could check to see what has focus before doing anything, so not change state if the editbox has focus.
 
You could put a procedure in like:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
Edit2.SetFocus;
Key := #$0;
end;


and pull the focus away from edit1


Regards and HTH,
JGS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top