Recent

Author Topic: Reintroduce events and properties suppressed in ancestors?  (Read 289 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1146
    • HowTos Considered Harmful?
Reintroduce events and properties suppressed in ancestors?
« on: October 05, 2024, 12:00:38 am »
I need to create a panel type component that can respond to key strokes and when I observe the hierarchy of TPanel it is descended from TWinControl which handles the key events which have been suppressed by the closer ancestors in the component hierarchy.

Do I have to create new control derived from TWinControl or can I inherit from TPanel and restore them?

This link Overriding and redeclaring properties suggests it is possible, but the keyboard events are removed from TCustomPanel and TCustomControl
Lazarus 3.0/FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: Reintroduce events and properties suppressed in ancestors?
« Reply #1 on: October 05, 2024, 12:17:33 am »
I don't know what you are talking about?

Code: Pascal  [Select][+][-]
  1. uses
  2.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, PairSplitter, ExtCtrls,
  3.   StdCtrls;
  4.  
  5. type
  6.  
  7.   { TForm1 }
  8.  
  9.   TForm1 = class(TForm)
  10.     Panel1: TPanel;
  11.     procedure AKeyPress(Sender: TObject; var Key: char);
  12.     procedure Panel1Click(Sender: TObject);
  13.   private
  14.  
  15.   public
  16.  
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.lfm}
  25.  
  26. { TForm1 }
  27.  
  28. procedure TForm1.AKeyPress(Sender: TObject; var Key: char);
  29. begin
  30.   beep;
  31. end;
  32.  
  33. procedure TForm1.Panel1Click(Sender: TObject);
  34. begin
  35.   Panel1.SetFocus;
  36.   Panel1.OnKeyPress := @AKeyPress;
  37. end;
  38.  
  39.  

First click on the panel to get it to focus.
The only true wisdom is knowing you know nothing

vfclists

  • Hero Member
  • *****
  • Posts: 1146
    • HowTos Considered Harmful?
Re: Reintroduce events and properties suppressed in ancestors?
« Reply #2 on: October 05, 2024, 01:17:39 am »
I have created a descendant of TPanel which responds to key events.

What I need now is for it to have some kind of KeyPreview property so that it too can intercept keystrokes meant for controls placed on it.
Lazarus 3.0/FPC 3.2.2

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1242
Re: Reintroduce events and properties suppressed in ancestors?
« Reply #3 on: October 05, 2024, 01:58:28 am »
I have done things similar to this with change events when I want the parent control to intercept events for child controls.

You can call the keydown event for child control from inside the parent control keydown event handler. You will need to identify what sent the event using “is” and typecast the sender too
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

 

TinyPortal © 2005-2018