Jump to content

onkeydown on frame


playsoft

Recommended Posts

1. Interface:

unit UKeyDown;

interface

uses
  System.Classes;

type
  IKeyDown = Interface
    ['{C21C434B-E6F7-4E2C-98CB-3ACC526566BE}']
    procedure FnKeyDown(Sender: TObject; Key: Word; Shift: TShiftState);
  End;

implementation

end.

2. In each Frame:

Uses
  ... UKeyDown;


type
  TfraTest = class(TUniFrame, IKeyDown)
  ...
  public
    procedure FnKeyDown(Sender: TObject; Key: Word; Shift: TShiftState);
  end;

procedure TfraTest.FnKeyDown(Sender: TObject; Key: Word; Shift: TShiftState);
begin
  case Key of
    VK_F1: begin
      ShowMessage(scKeys.Strings.Text);
    end;
    ...
  end;
end;

In MainForm: 

var
  ts: TUniTabSheet;
  i: Integer;
  fr: TUniFrame;
  kd: IKeyDown;
begin
  case Key of
    VK_F1..VK_F10: begin
      ts := PageCtrl.ActivePage;
      if ts = nil then begin
        EXIT;
      end;
      fr := nil;
      for i := 0 to ts.ControlCount - 2 do begin
        if ((ts.Controls[i] is TUniFrame) and (ts.Controls[i+1] is TUniSimplePanel) and (ts.Controls[i+1].Visible)) then begin
          fr := TUniFrame(ts.Controls[i]);
          BREAK;
        end;
      end;
      if fr <> nil then begin
        if Supports(fr, IKeyDown, kd) then
          kd.FnKeyDown(Sender, Key, Shift);
      end;
    end;
  end;
end;

=> I have a Pagecontrol with tabsheets and on each tabsheet there are one or more frames, but only one frame is visible. And this active frame I search for and call FnKeyDown.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...