Jump to content

Oliver Morsch

uniGUI Subscriber
  • Posts

    356
  • Joined

  • Last visited

  • Days Won

    18

Posts posted by Oliver Morsch

  1. 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.

×
×
  • Create New...