Simple_Application_Framework_for_VCL[5]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 zblue78 的 blog

now we need set-up our menu system and navigation controls, so that the end user may navigate through our modules.

[delphi]

constructor tfrmmain.create(aowner: tcomponent);
begin 
  inherited create(aowner);
  // set up menu and navigation controls 
  registermodules;
  // show the first module at start-up 
  if moduleinfomanager.count > 0 then 
    showmodule(moduleinfomanager[0].name);
end;

procedure tfrmmain.registermodules;
var
  i: integer;
  amenuitem: tmenuitem;
begin 
  //go through all modules 
  for i := 0 to moduleinfomanager.count - 1 do 
  begin
    // add item into list box 
    lblnavigation.items.add(moduleinfomanager[i].name);
    // add new sub menu item 
    amenuitem := tmenuitem.create(self);
    mview.add(amenuitem); 
    amenuitem.caption := moduleinfomanager[i].name;
    // use tag to identify the module 
    amenuitem.tag := i;
    amenuitem.onclick := mviewclick;
  end;
end;

procedure tfrmmain.showmodule(const aname: string);
begin 
  // lock windows updates for the main window during showing the module 
  lockwindowupdate(handle);
  try 
    moduleinfomanager.showmodule(aname, pnlworkingarea);
  finally 
    // refresh the main window 
    lockwindowupdate(0);
    redrawwindow(handle, nil, 0, rdw_erase or rdw_frame or rdw_invalidate or rdw_allchildren);
  end;
end;

procedure tfrmmain.lblnavigationclick(sender: tobject);
begin 
  if lblnavigation.itemindex < 0 then exit;
  // show the module 
  showmodule(lblnavigation.items[lblnavigation.itemindex]);
end;

procedure tfrmmain.mviewclick(sender: tobject);
begin 
  // show the module 
  showmodule(lblnavigation.items[tmenuitem(sender).tag]);
end;

the last step is to create new modules and register them into our application framework

[delphi]

unit module1;

interface 

uses 
  windows, messages, sysutils, variants, classes, graphics, controls, forms,
  dialogs, custommodule, stdctrls, modules;

type 
  //the module has to be inherited from the custom module class 
  tfrmmodule1 = class(tfrmcustommodule)
    label1: tlabel;
  private 
    { private declarations } 
  public 
    { public declarations } 
  end;

implementation 

{$r *.dfm} 

initialization 
  // register the class within our application framework 
  moduleinfomanager.registermodule('module1', tfrmmodule1);

end.

本文关键:Simple_Application_Framework_for_VCL
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top