mainctrl.pas

来自「Delphi利用MVC开发的典型例子」· PAS 代码 · 共 69 行

PAS
69
字号
unit MainCtrl;

interface
uses
  SysUtils, windows, forms, buttons, classes, Menus, controls, patterns,
  MainView, toolbox, commandlist;

type
  TControllerMain = class(TController)
    view: TViewMain;
  protected
    procedure DoCommand(Command: string; const args: string=''); override;
  public
    constructor Create;
    procedure OnClick(Sender: TObject); //for ieventListener
    procedure OnMouseEvent(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  end;

implementation

procedure TControllerMain.OnClick(Sender: TObject);
begin
  if (Sender is TMenuItem) then
  begin
    if TMenuItem(Sender).Caption = CMD_FILE_EXIT then
      view.Close
    else if TMenuItem(Sender).Caption = CMD_SHOW_HELP then
      Application.HelpCommand(HELP_CONTENTS, 0)
    else
      self.SendCommand(TMenuItem(Sender).Caption);
  end
  else if (Sender is TSpeedButton) then
  begin
    if TSpeedButton(Sender).Caption = CMD_BTN_CLOSE then
      view.Close
    else if TSpeedButton(Sender).Caption = CMD_BTN_HELP then
      Application.HelpCommand(HELP_CONTENTS, 0)
    else
      self.SendCommand(TSpeedButton(Sender).Caption);
  end;
end;

procedure TControllerMain.OnMouseEvent(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin

end;

constructor TControllerMain.Create;
begin
  inherited;
  Application.CreateForm(TViewMain, view);
  view.setEventListener(self.OnClick);
end;


procedure TControllerMain.DoCommand(Command: string; const args: string='');
begin
  if Command = CMD_SYSTEM_START then
    view.Show;
end;

initialization
  ControlCenter.RegController(TControllerMain.Create);

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?