mainctrl.pas

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

PAS
69
字号
unit MainCtrl;

interface
uses
  SysUtils, forms, buttons, classes, menus, controls, patterns,
  MainMdl, MainView;

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

implementation
uses
  commandlist;

procedure TControllerMain.OnClick(Sender: TObject);
begin
  if not assigned(sender) then exit;

  if (sender is Tmenuitem) then
  begin
    if (TMenuItem(Sender).caption = '&About...') then
      self.sendCommand(CMD_SHOW_ABOUT)
    else if (TMenuItem(Sender).caption = '&Help') then
      application.MessageBox('Help menu selected!', 'Help', 0);
  end;
end;

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

end;

constructor TControllerMain.Create;
begin
  inherited;
  model := TModelMain.Create;
  Application.CreateForm(TViewMain, view);
  view.setNotifyEventHandler(self.onClick);
  model.RegObserver(view);
end;

destructor TControllerMain.destroy;
begin
  freeAndNil(model);
  inherited;
end;

procedure TControllerMain.DoCommand(Command: string; const args: string = '');
begin
end;

initialization
  ControlCenter.RegController(TControllerMain.Create);

end.

 

⌨️ 快捷键说明

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